
USE [ITViet]
GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblAdvertiseLocale_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblAdvertiseLocale_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblAdvertiseLocale_Get_List
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Gets all records from the tblAdvertiseLocale table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblAdvertiseLocale_Get_List

AS


				
				SELECT
					[Id],
					[AdvertiseId],
					[LanguageId],
					[Name]
				FROM
					[dbo].[tblAdvertiseLocale]
					
				SELECT @@ROWCOUNT
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblAdvertiseLocale_GetPaged procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblAdvertiseLocale_GetPaged') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblAdvertiseLocale_GetPaged
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Gets records from the tblAdvertiseLocale table passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblAdvertiseLocale_GetPaged
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				
				BEGIN
				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				-- Create a temp table to store the select results
				CREATE TABLE #PageIndex
				(
				    [IndexId] int IDENTITY (1, 1) NOT NULL,
				    [Id] int 
				)
				
				-- Insert into the temp table
				DECLARE @SQL AS nvarchar(4000)
				SET @SQL = 'INSERT INTO #PageIndex ([Id])'
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + CONVERT(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' [Id]'
				SET @SQL = @SQL + ' FROM [dbo].[tblAdvertiseLocale]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				IF LEN(@OrderBy) > 0
				BEGIN
					SET @SQL = @SQL + ' ORDER BY ' + @OrderBy
				END
				
				-- Populate the temp table
				EXEC sp_executesql @SQL

				-- Return paged results
				SELECT O.[Id], O.[AdvertiseId], O.[LanguageId], O.[Name]
				FROM
				    [dbo].[tblAdvertiseLocale] O,
				    #PageIndex PageIndex
				WHERE
				    PageIndex.IndexId > @PageLowerBound
					AND O.[Id] = PageIndex.[Id]
				ORDER BY
				    PageIndex.IndexId
				
				-- get row count
				SET @SQL = 'SELECT COUNT(*) AS TotalRowCount'
				SET @SQL = @SQL + ' FROM [dbo].[tblAdvertiseLocale]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				EXEC sp_executesql @SQL
			
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblAdvertiseLocale_Insert procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblAdvertiseLocale_Insert') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblAdvertiseLocale_Insert
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Inserts a record into the tblAdvertiseLocale table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblAdvertiseLocale_Insert
(

	@Id int    OUTPUT,

	@AdvertiseId int   ,

	@LanguageId int   ,

	@Name nvarchar (128)  
)
AS


				
				INSERT INTO [dbo].[tblAdvertiseLocale]
					(
					[AdvertiseId]
					,[LanguageId]
					,[Name]
					)
				VALUES
					(
					@AdvertiseId
					,@LanguageId
					,@Name
					)
				
				-- Get the identity value
				SET @Id = SCOPE_IDENTITY()
									
							
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblAdvertiseLocale_Update procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblAdvertiseLocale_Update') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblAdvertiseLocale_Update
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Updates a record in the tblAdvertiseLocale table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblAdvertiseLocale_Update
(

	@Id int   ,

	@AdvertiseId int   ,

	@LanguageId int   ,

	@Name nvarchar (128)  
)
AS


				
				
				-- Modify the updatable columns
				UPDATE
					[dbo].[tblAdvertiseLocale]
				SET
					[AdvertiseId] = @AdvertiseId
					,[LanguageId] = @LanguageId
					,[Name] = @Name
				WHERE
[Id] = @Id 
				
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblAdvertiseLocale_Delete procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblAdvertiseLocale_Delete') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblAdvertiseLocale_Delete
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Deletes a record in the tblAdvertiseLocale table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblAdvertiseLocale_Delete
(

	@Id int   
)
AS


				DELETE FROM [dbo].[tblAdvertiseLocale] WITH (ROWLOCK) 
				WHERE
					[Id] = @Id
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblAdvertiseLocale_GetByLanguageId procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblAdvertiseLocale_GetByLanguageId') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblAdvertiseLocale_GetByLanguageId
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Select records from the tblAdvertiseLocale table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblAdvertiseLocale_GetByLanguageId
(

	@LanguageId int   
)
AS


				SET ANSI_NULLS OFF
				
				SELECT
					[Id],
					[AdvertiseId],
					[LanguageId],
					[Name]
				FROM
					[dbo].[tblAdvertiseLocale]
				WHERE
					[LanguageId] = @LanguageId
				
				SELECT @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblAdvertiseLocale_GetById procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblAdvertiseLocale_GetById') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblAdvertiseLocale_GetById
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Select records from the tblAdvertiseLocale table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblAdvertiseLocale_GetById
(

	@Id int   
)
AS


				SELECT
					[Id],
					[AdvertiseId],
					[LanguageId],
					[Name]
				FROM
					[dbo].[tblAdvertiseLocale]
				WHERE
					[Id] = @Id
				SELECT @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblAdvertiseLocale_Find procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblAdvertiseLocale_Find') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblAdvertiseLocale_Find
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Finds records in the tblAdvertiseLocale table passing nullable parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblAdvertiseLocale_Find
(

	@SearchUsingOR bit   = null ,

	@Id int   = null ,

	@AdvertiseId int   = null ,

	@LanguageId int   = null ,

	@Name nvarchar (128)  = null 
)
AS


				
  IF ISNULL(@SearchUsingOR, 0) <> 1
  BEGIN
    SELECT
	  [Id]
	, [AdvertiseId]
	, [LanguageId]
	, [Name]
    FROM
	[dbo].[tblAdvertiseLocale]
    WHERE 
	 ([Id] = @Id OR @Id IS NULL)
	AND ([AdvertiseId] = @AdvertiseId OR @AdvertiseId IS NULL)
	AND ([LanguageId] = @LanguageId OR @LanguageId IS NULL)
	AND ([Name] = @Name OR @Name IS NULL)
						
  END
  ELSE
  BEGIN
    SELECT
	  [Id]
	, [AdvertiseId]
	, [LanguageId]
	, [Name]
    FROM
	[dbo].[tblAdvertiseLocale]
    WHERE 
	 ([Id] = @Id AND @Id is not null)
	OR ([AdvertiseId] = @AdvertiseId AND @AdvertiseId is not null)
	OR ([LanguageId] = @LanguageId AND @LanguageId is not null)
	OR ([Name] = @Name AND @Name is not null)
	SELECT @@ROWCOUNT			
  END
				

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblProductCategory_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblProductCategory_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblProductCategory_Get_List
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Gets all records from the tblProductCategory table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblProductCategory_Get_List

AS


				
				SELECT
					[Id],
					[Code],
					[Name],
					[ParentId],
					[CreatedDate],
					[CreatedBy]
				FROM
					[dbo].[tblProductCategory]
					
				SELECT @@ROWCOUNT
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblProductCategory_GetPaged procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblProductCategory_GetPaged') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblProductCategory_GetPaged
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Gets records from the tblProductCategory table passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblProductCategory_GetPaged
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				
				BEGIN
				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				-- Create a temp table to store the select results
				CREATE TABLE #PageIndex
				(
				    [IndexId] int IDENTITY (1, 1) NOT NULL,
				    [Id] int 
				)
				
				-- Insert into the temp table
				DECLARE @SQL AS nvarchar(4000)
				SET @SQL = 'INSERT INTO #PageIndex ([Id])'
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + CONVERT(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' [Id]'
				SET @SQL = @SQL + ' FROM [dbo].[tblProductCategory]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				IF LEN(@OrderBy) > 0
				BEGIN
					SET @SQL = @SQL + ' ORDER BY ' + @OrderBy
				END
				
				-- Populate the temp table
				EXEC sp_executesql @SQL

				-- Return paged results
				SELECT O.[Id], O.[Code], O.[Name], O.[ParentId], O.[CreatedDate], O.[CreatedBy]
				FROM
				    [dbo].[tblProductCategory] O,
				    #PageIndex PageIndex
				WHERE
				    PageIndex.IndexId > @PageLowerBound
					AND O.[Id] = PageIndex.[Id]
				ORDER BY
				    PageIndex.IndexId
				
				-- get row count
				SET @SQL = 'SELECT COUNT(*) AS TotalRowCount'
				SET @SQL = @SQL + ' FROM [dbo].[tblProductCategory]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				EXEC sp_executesql @SQL
			
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblProductCategory_Insert procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblProductCategory_Insert') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblProductCategory_Insert
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Inserts a record into the tblProductCategory table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblProductCategory_Insert
(

	@Id int    OUTPUT,

	@Code varchar (128)  ,

	@Name nvarchar (128)  ,

	@ParentId int   ,

	@CreatedDate datetime   ,

	@CreatedBy varchar (50)  
)
AS


				
				INSERT INTO [dbo].[tblProductCategory]
					(
					[Code]
					,[Name]
					,[ParentId]
					,[CreatedDate]
					,[CreatedBy]
					)
				VALUES
					(
					@Code
					,@Name
					,@ParentId
					,@CreatedDate
					,@CreatedBy
					)
				
				-- Get the identity value
				SET @Id = SCOPE_IDENTITY()
									
							
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblProductCategory_Update procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblProductCategory_Update') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblProductCategory_Update
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Updates a record in the tblProductCategory table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblProductCategory_Update
(

	@Id int   ,

	@Code varchar (128)  ,

	@Name nvarchar (128)  ,

	@ParentId int   ,

	@CreatedDate datetime   ,

	@CreatedBy varchar (50)  
)
AS


				
				
				-- Modify the updatable columns
				UPDATE
					[dbo].[tblProductCategory]
				SET
					[Code] = @Code
					,[Name] = @Name
					,[ParentId] = @ParentId
					,[CreatedDate] = @CreatedDate
					,[CreatedBy] = @CreatedBy
				WHERE
[Id] = @Id 
				
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblProductCategory_Delete procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblProductCategory_Delete') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblProductCategory_Delete
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Deletes a record in the tblProductCategory table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblProductCategory_Delete
(

	@Id int   
)
AS


				DELETE FROM [dbo].[tblProductCategory] WITH (ROWLOCK) 
				WHERE
					[Id] = @Id
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblProductCategory_GetById procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblProductCategory_GetById') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblProductCategory_GetById
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Select records from the tblProductCategory table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblProductCategory_GetById
(

	@Id int   
)
AS


				SELECT
					[Id],
					[Code],
					[Name],
					[ParentId],
					[CreatedDate],
					[CreatedBy]
				FROM
					[dbo].[tblProductCategory]
				WHERE
					[Id] = @Id
				SELECT @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblProductCategory_GetByCode procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblProductCategory_GetByCode') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblProductCategory_GetByCode
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Select records from the tblProductCategory table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblProductCategory_GetByCode
(

	@Code varchar (128)  
)
AS


				SELECT
					[Id],
					[Code],
					[Name],
					[ParentId],
					[CreatedDate],
					[CreatedBy]
				FROM
					[dbo].[tblProductCategory]
				WHERE
					[Code] = @Code
				SELECT @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblProductCategory_Find procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblProductCategory_Find') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblProductCategory_Find
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Finds records in the tblProductCategory table passing nullable parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblProductCategory_Find
(

	@SearchUsingOR bit   = null ,

	@Id int   = null ,

	@Code varchar (128)  = null ,

	@Name nvarchar (128)  = null ,

	@ParentId int   = null ,

	@CreatedDate datetime   = null ,

	@CreatedBy varchar (50)  = null 
)
AS


				
  IF ISNULL(@SearchUsingOR, 0) <> 1
  BEGIN
    SELECT
	  [Id]
	, [Code]
	, [Name]
	, [ParentId]
	, [CreatedDate]
	, [CreatedBy]
    FROM
	[dbo].[tblProductCategory]
    WHERE 
	 ([Id] = @Id OR @Id IS NULL)
	AND ([Code] = @Code OR @Code IS NULL)
	AND ([Name] = @Name OR @Name IS NULL)
	AND ([ParentId] = @ParentId OR @ParentId IS NULL)
	AND ([CreatedDate] = @CreatedDate OR @CreatedDate IS NULL)
	AND ([CreatedBy] = @CreatedBy OR @CreatedBy IS NULL)
						
  END
  ELSE
  BEGIN
    SELECT
	  [Id]
	, [Code]
	, [Name]
	, [ParentId]
	, [CreatedDate]
	, [CreatedBy]
    FROM
	[dbo].[tblProductCategory]
    WHERE 
	 ([Id] = @Id AND @Id is not null)
	OR ([Code] = @Code AND @Code is not null)
	OR ([Name] = @Name AND @Name is not null)
	OR ([ParentId] = @ParentId AND @ParentId is not null)
	OR ([CreatedDate] = @CreatedDate AND @CreatedDate is not null)
	OR ([CreatedBy] = @CreatedBy AND @CreatedBy is not null)
	SELECT @@ROWCOUNT			
  END
				

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblProduct_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblProduct_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblProduct_Get_List
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Gets all records from the tblProduct table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblProduct_Get_List

AS


				
				SELECT
					[Id],
					[Code],
					[Name],
					[CategoryId],
					[CreatedDate],
					[CreatedBy],
					[ModifiedDate],
					[ModifiedBy],
					[Image],
					[Color],
					[Size],
					[AlbumId],
					[HasInventory],
					[IsHot]
				FROM
					[dbo].[tblProduct]
					
				SELECT @@ROWCOUNT
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblProduct_GetPaged procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblProduct_GetPaged') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblProduct_GetPaged
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Gets records from the tblProduct table passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblProduct_GetPaged
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				
				BEGIN
				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				-- Create a temp table to store the select results
				CREATE TABLE #PageIndex
				(
				    [IndexId] int IDENTITY (1, 1) NOT NULL,
				    [Id] int 
				)
				
				-- Insert into the temp table
				DECLARE @SQL AS nvarchar(4000)
				SET @SQL = 'INSERT INTO #PageIndex ([Id])'
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + CONVERT(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' [Id]'
				SET @SQL = @SQL + ' FROM [dbo].[tblProduct]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				IF LEN(@OrderBy) > 0
				BEGIN
					SET @SQL = @SQL + ' ORDER BY ' + @OrderBy
				END
				
				-- Populate the temp table
				EXEC sp_executesql @SQL

				-- Return paged results
				SELECT O.[Id], O.[Code], O.[Name], O.[CategoryId], O.[CreatedDate], O.[CreatedBy], O.[ModifiedDate], O.[ModifiedBy], O.[Image], O.[Color], O.[Size], O.[AlbumId], O.[HasInventory], O.[IsHot]
				FROM
				    [dbo].[tblProduct] O,
				    #PageIndex PageIndex
				WHERE
				    PageIndex.IndexId > @PageLowerBound
					AND O.[Id] = PageIndex.[Id]
				ORDER BY
				    PageIndex.IndexId
				
				-- get row count
				SET @SQL = 'SELECT COUNT(*) AS TotalRowCount'
				SET @SQL = @SQL + ' FROM [dbo].[tblProduct]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				EXEC sp_executesql @SQL
			
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblProduct_Insert procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblProduct_Insert') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblProduct_Insert
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Inserts a record into the tblProduct table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblProduct_Insert
(

	@Id int    OUTPUT,

	@Code varchar (128)  ,

	@Name nvarchar (128)  ,

	@CategoryId int   ,

	@CreatedDate datetime   ,

	@CreatedBy varchar (50)  ,

	@ModifiedDate datetime   ,

	@ModifiedBy varchar (50)  ,

	@Image nvarchar (256)  ,

	@Color varchar (256)  ,

	@Size varchar (256)  ,

	@AlbumId int   ,

	@HasInventory bit   ,

	@IsHot bit   
)
AS


				
				INSERT INTO [dbo].[tblProduct]
					(
					[Code]
					,[Name]
					,[CategoryId]
					,[CreatedDate]
					,[CreatedBy]
					,[ModifiedDate]
					,[ModifiedBy]
					,[Image]
					,[Color]
					,[Size]
					,[AlbumId]
					,[HasInventory]
					,[IsHot]
					)
				VALUES
					(
					@Code
					,@Name
					,@CategoryId
					,@CreatedDate
					,@CreatedBy
					,@ModifiedDate
					,@ModifiedBy
					,@Image
					,@Color
					,@Size
					,@AlbumId
					,@HasInventory
					,@IsHot
					)
				
				-- Get the identity value
				SET @Id = SCOPE_IDENTITY()
									
							
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblProduct_Update procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblProduct_Update') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblProduct_Update
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Updates a record in the tblProduct table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblProduct_Update
(

	@Id int   ,

	@Code varchar (128)  ,

	@Name nvarchar (128)  ,

	@CategoryId int   ,

	@CreatedDate datetime   ,

	@CreatedBy varchar (50)  ,

	@ModifiedDate datetime   ,

	@ModifiedBy varchar (50)  ,

	@Image nvarchar (256)  ,

	@Color varchar (256)  ,

	@Size varchar (256)  ,

	@AlbumId int   ,

	@HasInventory bit   ,

	@IsHot bit   
)
AS


				
				
				-- Modify the updatable columns
				UPDATE
					[dbo].[tblProduct]
				SET
					[Code] = @Code
					,[Name] = @Name
					,[CategoryId] = @CategoryId
					,[CreatedDate] = @CreatedDate
					,[CreatedBy] = @CreatedBy
					,[ModifiedDate] = @ModifiedDate
					,[ModifiedBy] = @ModifiedBy
					,[Image] = @Image
					,[Color] = @Color
					,[Size] = @Size
					,[AlbumId] = @AlbumId
					,[HasInventory] = @HasInventory
					,[IsHot] = @IsHot
				WHERE
[Id] = @Id 
				
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblProduct_Delete procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblProduct_Delete') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblProduct_Delete
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Deletes a record in the tblProduct table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblProduct_Delete
(

	@Id int   
)
AS


				DELETE FROM [dbo].[tblProduct] WITH (ROWLOCK) 
				WHERE
					[Id] = @Id
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblProduct_GetByCategoryId procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblProduct_GetByCategoryId') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblProduct_GetByCategoryId
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Select records from the tblProduct table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblProduct_GetByCategoryId
(

	@CategoryId int   
)
AS


				SET ANSI_NULLS OFF
				
				SELECT
					[Id],
					[Code],
					[Name],
					[CategoryId],
					[CreatedDate],
					[CreatedBy],
					[ModifiedDate],
					[ModifiedBy],
					[Image],
					[Color],
					[Size],
					[AlbumId],
					[HasInventory],
					[IsHot]
				FROM
					[dbo].[tblProduct]
				WHERE
					[CategoryId] = @CategoryId
				
				SELECT @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblProduct_GetById procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblProduct_GetById') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblProduct_GetById
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Select records from the tblProduct table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblProduct_GetById
(

	@Id int   
)
AS


				SELECT
					[Id],
					[Code],
					[Name],
					[CategoryId],
					[CreatedDate],
					[CreatedBy],
					[ModifiedDate],
					[ModifiedBy],
					[Image],
					[Color],
					[Size],
					[AlbumId],
					[HasInventory],
					[IsHot]
				FROM
					[dbo].[tblProduct]
				WHERE
					[Id] = @Id
				SELECT @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblProduct_GetByCode procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblProduct_GetByCode') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblProduct_GetByCode
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Select records from the tblProduct table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblProduct_GetByCode
(

	@Code varchar (128)  
)
AS


				SELECT
					[Id],
					[Code],
					[Name],
					[CategoryId],
					[CreatedDate],
					[CreatedBy],
					[ModifiedDate],
					[ModifiedBy],
					[Image],
					[Color],
					[Size],
					[AlbumId],
					[HasInventory],
					[IsHot]
				FROM
					[dbo].[tblProduct]
				WHERE
					[Code] = @Code
				SELECT @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblProduct_Find procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblProduct_Find') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblProduct_Find
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Finds records in the tblProduct table passing nullable parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblProduct_Find
(

	@SearchUsingOR bit   = null ,

	@Id int   = null ,

	@Code varchar (128)  = null ,

	@Name nvarchar (128)  = null ,

	@CategoryId int   = null ,

	@CreatedDate datetime   = null ,

	@CreatedBy varchar (50)  = null ,

	@ModifiedDate datetime   = null ,

	@ModifiedBy varchar (50)  = null ,

	@Image nvarchar (256)  = null ,

	@Color varchar (256)  = null ,

	@Size varchar (256)  = null ,

	@AlbumId int   = null ,

	@HasInventory bit   = null ,

	@IsHot bit   = null 
)
AS


				
  IF ISNULL(@SearchUsingOR, 0) <> 1
  BEGIN
    SELECT
	  [Id]
	, [Code]
	, [Name]
	, [CategoryId]
	, [CreatedDate]
	, [CreatedBy]
	, [ModifiedDate]
	, [ModifiedBy]
	, [Image]
	, [Color]
	, [Size]
	, [AlbumId]
	, [HasInventory]
	, [IsHot]
    FROM
	[dbo].[tblProduct]
    WHERE 
	 ([Id] = @Id OR @Id IS NULL)
	AND ([Code] = @Code OR @Code IS NULL)
	AND ([Name] = @Name OR @Name IS NULL)
	AND ([CategoryId] = @CategoryId OR @CategoryId IS NULL)
	AND ([CreatedDate] = @CreatedDate OR @CreatedDate IS NULL)
	AND ([CreatedBy] = @CreatedBy OR @CreatedBy IS NULL)
	AND ([ModifiedDate] = @ModifiedDate OR @ModifiedDate IS NULL)
	AND ([ModifiedBy] = @ModifiedBy OR @ModifiedBy IS NULL)
	AND ([Image] = @Image OR @Image IS NULL)
	AND ([Color] = @Color OR @Color IS NULL)
	AND ([Size] = @Size OR @Size IS NULL)
	AND ([AlbumId] = @AlbumId OR @AlbumId IS NULL)
	AND ([HasInventory] = @HasInventory OR @HasInventory IS NULL)
	AND ([IsHot] = @IsHot OR @IsHot IS NULL)
						
  END
  ELSE
  BEGIN
    SELECT
	  [Id]
	, [Code]
	, [Name]
	, [CategoryId]
	, [CreatedDate]
	, [CreatedBy]
	, [ModifiedDate]
	, [ModifiedBy]
	, [Image]
	, [Color]
	, [Size]
	, [AlbumId]
	, [HasInventory]
	, [IsHot]
    FROM
	[dbo].[tblProduct]
    WHERE 
	 ([Id] = @Id AND @Id is not null)
	OR ([Code] = @Code AND @Code is not null)
	OR ([Name] = @Name AND @Name is not null)
	OR ([CategoryId] = @CategoryId AND @CategoryId is not null)
	OR ([CreatedDate] = @CreatedDate AND @CreatedDate is not null)
	OR ([CreatedBy] = @CreatedBy AND @CreatedBy is not null)
	OR ([ModifiedDate] = @ModifiedDate AND @ModifiedDate is not null)
	OR ([ModifiedBy] = @ModifiedBy AND @ModifiedBy is not null)
	OR ([Image] = @Image AND @Image is not null)
	OR ([Color] = @Color AND @Color is not null)
	OR ([Size] = @Size AND @Size is not null)
	OR ([AlbumId] = @AlbumId AND @AlbumId is not null)
	OR ([HasInventory] = @HasInventory AND @HasInventory is not null)
	OR ([IsHot] = @IsHot AND @IsHot is not null)
	SELECT @@ROWCOUNT			
  END
				

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblProCategoryLocale_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblProCategoryLocale_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblProCategoryLocale_Get_List
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Gets all records from the tblProCategoryLocale table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblProCategoryLocale_Get_List

AS


				
				SELECT
					[Id],
					[CategoryId],
					[LanguageId],
					[Name],
					[Description]
				FROM
					[dbo].[tblProCategoryLocale]
					
				SELECT @@ROWCOUNT
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblProCategoryLocale_GetPaged procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblProCategoryLocale_GetPaged') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblProCategoryLocale_GetPaged
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Gets records from the tblProCategoryLocale table passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblProCategoryLocale_GetPaged
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				
				BEGIN
				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				-- Create a temp table to store the select results
				CREATE TABLE #PageIndex
				(
				    [IndexId] int IDENTITY (1, 1) NOT NULL,
				    [Id] int 
				)
				
				-- Insert into the temp table
				DECLARE @SQL AS nvarchar(4000)
				SET @SQL = 'INSERT INTO #PageIndex ([Id])'
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + CONVERT(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' [Id]'
				SET @SQL = @SQL + ' FROM [dbo].[tblProCategoryLocale]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				IF LEN(@OrderBy) > 0
				BEGIN
					SET @SQL = @SQL + ' ORDER BY ' + @OrderBy
				END
				
				-- Populate the temp table
				EXEC sp_executesql @SQL

				-- Return paged results
				SELECT O.[Id], O.[CategoryId], O.[LanguageId], O.[Name], O.[Description]
				FROM
				    [dbo].[tblProCategoryLocale] O,
				    #PageIndex PageIndex
				WHERE
				    PageIndex.IndexId > @PageLowerBound
					AND O.[Id] = PageIndex.[Id]
				ORDER BY
				    PageIndex.IndexId
				
				-- get row count
				SET @SQL = 'SELECT COUNT(*) AS TotalRowCount'
				SET @SQL = @SQL + ' FROM [dbo].[tblProCategoryLocale]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				EXEC sp_executesql @SQL
			
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblProCategoryLocale_Insert procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblProCategoryLocale_Insert') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblProCategoryLocale_Insert
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Inserts a record into the tblProCategoryLocale table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblProCategoryLocale_Insert
(

	@Id int    OUTPUT,

	@CategoryId int   ,

	@LanguageId int   ,

	@Name nvarchar (128)  ,

	@Description nvarchar (1024)  
)
AS


				
				INSERT INTO [dbo].[tblProCategoryLocale]
					(
					[CategoryId]
					,[LanguageId]
					,[Name]
					,[Description]
					)
				VALUES
					(
					@CategoryId
					,@LanguageId
					,@Name
					,@Description
					)
				
				-- Get the identity value
				SET @Id = SCOPE_IDENTITY()
									
							
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblProCategoryLocale_Update procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblProCategoryLocale_Update') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblProCategoryLocale_Update
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Updates a record in the tblProCategoryLocale table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblProCategoryLocale_Update
(

	@Id int   ,

	@CategoryId int   ,

	@LanguageId int   ,

	@Name nvarchar (128)  ,

	@Description nvarchar (1024)  
)
AS


				
				
				-- Modify the updatable columns
				UPDATE
					[dbo].[tblProCategoryLocale]
				SET
					[CategoryId] = @CategoryId
					,[LanguageId] = @LanguageId
					,[Name] = @Name
					,[Description] = @Description
				WHERE
[Id] = @Id 
				
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblProCategoryLocale_Delete procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblProCategoryLocale_Delete') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblProCategoryLocale_Delete
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Deletes a record in the tblProCategoryLocale table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblProCategoryLocale_Delete
(

	@Id int   
)
AS


				DELETE FROM [dbo].[tblProCategoryLocale] WITH (ROWLOCK) 
				WHERE
					[Id] = @Id
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblProCategoryLocale_GetByCategoryId procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblProCategoryLocale_GetByCategoryId') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblProCategoryLocale_GetByCategoryId
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Select records from the tblProCategoryLocale table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblProCategoryLocale_GetByCategoryId
(

	@CategoryId int   
)
AS


				SET ANSI_NULLS OFF
				
				SELECT
					[Id],
					[CategoryId],
					[LanguageId],
					[Name],
					[Description]
				FROM
					[dbo].[tblProCategoryLocale]
				WHERE
					[CategoryId] = @CategoryId
				
				SELECT @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblProCategoryLocale_GetByLanguageId procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblProCategoryLocale_GetByLanguageId') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblProCategoryLocale_GetByLanguageId
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Select records from the tblProCategoryLocale table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblProCategoryLocale_GetByLanguageId
(

	@LanguageId int   
)
AS


				SET ANSI_NULLS OFF
				
				SELECT
					[Id],
					[CategoryId],
					[LanguageId],
					[Name],
					[Description]
				FROM
					[dbo].[tblProCategoryLocale]
				WHERE
					[LanguageId] = @LanguageId
				
				SELECT @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblProCategoryLocale_GetById procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblProCategoryLocale_GetById') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblProCategoryLocale_GetById
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Select records from the tblProCategoryLocale table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblProCategoryLocale_GetById
(

	@Id int   
)
AS


				SELECT
					[Id],
					[CategoryId],
					[LanguageId],
					[Name],
					[Description]
				FROM
					[dbo].[tblProCategoryLocale]
				WHERE
					[Id] = @Id
				SELECT @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblProCategoryLocale_Find procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblProCategoryLocale_Find') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblProCategoryLocale_Find
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Finds records in the tblProCategoryLocale table passing nullable parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblProCategoryLocale_Find
(

	@SearchUsingOR bit   = null ,

	@Id int   = null ,

	@CategoryId int   = null ,

	@LanguageId int   = null ,

	@Name nvarchar (128)  = null ,

	@Description nvarchar (1024)  = null 
)
AS


				
  IF ISNULL(@SearchUsingOR, 0) <> 1
  BEGIN
    SELECT
	  [Id]
	, [CategoryId]
	, [LanguageId]
	, [Name]
	, [Description]
    FROM
	[dbo].[tblProCategoryLocale]
    WHERE 
	 ([Id] = @Id OR @Id IS NULL)
	AND ([CategoryId] = @CategoryId OR @CategoryId IS NULL)
	AND ([LanguageId] = @LanguageId OR @LanguageId IS NULL)
	AND ([Name] = @Name OR @Name IS NULL)
	AND ([Description] = @Description OR @Description IS NULL)
						
  END
  ELSE
  BEGIN
    SELECT
	  [Id]
	, [CategoryId]
	, [LanguageId]
	, [Name]
	, [Description]
    FROM
	[dbo].[tblProCategoryLocale]
    WHERE 
	 ([Id] = @Id AND @Id is not null)
	OR ([CategoryId] = @CategoryId AND @CategoryId is not null)
	OR ([LanguageId] = @LanguageId AND @LanguageId is not null)
	OR ([Name] = @Name AND @Name is not null)
	OR ([Description] = @Description AND @Description is not null)
	SELECT @@ROWCOUNT			
  END
				

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblNewsCategory_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblNewsCategory_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblNewsCategory_Get_List
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Gets all records from the tblNewsCategory table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblNewsCategory_Get_List

AS


				
				SELECT
					[Id],
					[Code],
					[Name],
					[Type],
					[ParentId],
					[CreatedDate],
					[CreatedBy]
				FROM
					[dbo].[tblNewsCategory]
					
				SELECT @@ROWCOUNT
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblNewsCategory_GetPaged procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblNewsCategory_GetPaged') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblNewsCategory_GetPaged
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Gets records from the tblNewsCategory table passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblNewsCategory_GetPaged
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				
				BEGIN
				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				-- Create a temp table to store the select results
				CREATE TABLE #PageIndex
				(
				    [IndexId] int IDENTITY (1, 1) NOT NULL,
				    [Id] int 
				)
				
				-- Insert into the temp table
				DECLARE @SQL AS nvarchar(4000)
				SET @SQL = 'INSERT INTO #PageIndex ([Id])'
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + CONVERT(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' [Id]'
				SET @SQL = @SQL + ' FROM [dbo].[tblNewsCategory]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				IF LEN(@OrderBy) > 0
				BEGIN
					SET @SQL = @SQL + ' ORDER BY ' + @OrderBy
				END
				
				-- Populate the temp table
				EXEC sp_executesql @SQL

				-- Return paged results
				SELECT O.[Id], O.[Code], O.[Name], O.[Type], O.[ParentId], O.[CreatedDate], O.[CreatedBy]
				FROM
				    [dbo].[tblNewsCategory] O,
				    #PageIndex PageIndex
				WHERE
				    PageIndex.IndexId > @PageLowerBound
					AND O.[Id] = PageIndex.[Id]
				ORDER BY
				    PageIndex.IndexId
				
				-- get row count
				SET @SQL = 'SELECT COUNT(*) AS TotalRowCount'
				SET @SQL = @SQL + ' FROM [dbo].[tblNewsCategory]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				EXEC sp_executesql @SQL
			
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblNewsCategory_Insert procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblNewsCategory_Insert') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblNewsCategory_Insert
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Inserts a record into the tblNewsCategory table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblNewsCategory_Insert
(

	@Id int    OUTPUT,

	@Code varchar (128)  ,

	@Name nvarchar (128)  ,

	@Type char (1)  ,

	@ParentId int   ,

	@CreatedDate datetime   ,

	@CreatedBy varchar (50)  
)
AS


				
				INSERT INTO [dbo].[tblNewsCategory]
					(
					[Code]
					,[Name]
					,[Type]
					,[ParentId]
					,[CreatedDate]
					,[CreatedBy]
					)
				VALUES
					(
					@Code
					,@Name
					,@Type
					,@ParentId
					,@CreatedDate
					,@CreatedBy
					)
				
				-- Get the identity value
				SET @Id = SCOPE_IDENTITY()
									
							
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblNewsCategory_Update procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblNewsCategory_Update') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblNewsCategory_Update
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Updates a record in the tblNewsCategory table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblNewsCategory_Update
(

	@Id int   ,

	@Code varchar (128)  ,

	@Name nvarchar (128)  ,

	@Type char (1)  ,

	@ParentId int   ,

	@CreatedDate datetime   ,

	@CreatedBy varchar (50)  
)
AS


				
				
				-- Modify the updatable columns
				UPDATE
					[dbo].[tblNewsCategory]
				SET
					[Code] = @Code
					,[Name] = @Name
					,[Type] = @Type
					,[ParentId] = @ParentId
					,[CreatedDate] = @CreatedDate
					,[CreatedBy] = @CreatedBy
				WHERE
[Id] = @Id 
				
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblNewsCategory_Delete procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblNewsCategory_Delete') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblNewsCategory_Delete
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Deletes a record in the tblNewsCategory table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblNewsCategory_Delete
(

	@Id int   
)
AS


				DELETE FROM [dbo].[tblNewsCategory] WITH (ROWLOCK) 
				WHERE
					[Id] = @Id
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblNewsCategory_GetByParentId procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblNewsCategory_GetByParentId') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblNewsCategory_GetByParentId
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Select records from the tblNewsCategory table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblNewsCategory_GetByParentId
(

	@ParentId int   
)
AS


				SET ANSI_NULLS OFF
				
				SELECT
					[Id],
					[Code],
					[Name],
					[Type],
					[ParentId],
					[CreatedDate],
					[CreatedBy]
				FROM
					[dbo].[tblNewsCategory]
				WHERE
					[ParentId] = @ParentId
				
				SELECT @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblNewsCategory_GetById procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblNewsCategory_GetById') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblNewsCategory_GetById
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Select records from the tblNewsCategory table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblNewsCategory_GetById
(

	@Id int   
)
AS


				SELECT
					[Id],
					[Code],
					[Name],
					[Type],
					[ParentId],
					[CreatedDate],
					[CreatedBy]
				FROM
					[dbo].[tblNewsCategory]
				WHERE
					[Id] = @Id
				SELECT @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblNewsCategory_GetByCode procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblNewsCategory_GetByCode') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblNewsCategory_GetByCode
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Select records from the tblNewsCategory table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblNewsCategory_GetByCode
(

	@Code varchar (128)  
)
AS


				SELECT
					[Id],
					[Code],
					[Name],
					[Type],
					[ParentId],
					[CreatedDate],
					[CreatedBy]
				FROM
					[dbo].[tblNewsCategory]
				WHERE
					[Code] = @Code
				SELECT @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblNewsCategory_Find procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblNewsCategory_Find') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblNewsCategory_Find
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Finds records in the tblNewsCategory table passing nullable parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblNewsCategory_Find
(

	@SearchUsingOR bit   = null ,

	@Id int   = null ,

	@Code varchar (128)  = null ,

	@Name nvarchar (128)  = null ,

	@Type char (1)  = null ,

	@ParentId int   = null ,

	@CreatedDate datetime   = null ,

	@CreatedBy varchar (50)  = null 
)
AS


				
  IF ISNULL(@SearchUsingOR, 0) <> 1
  BEGIN
    SELECT
	  [Id]
	, [Code]
	, [Name]
	, [Type]
	, [ParentId]
	, [CreatedDate]
	, [CreatedBy]
    FROM
	[dbo].[tblNewsCategory]
    WHERE 
	 ([Id] = @Id OR @Id IS NULL)
	AND ([Code] = @Code OR @Code IS NULL)
	AND ([Name] = @Name OR @Name IS NULL)
	AND ([Type] = @Type OR @Type IS NULL)
	AND ([ParentId] = @ParentId OR @ParentId IS NULL)
	AND ([CreatedDate] = @CreatedDate OR @CreatedDate IS NULL)
	AND ([CreatedBy] = @CreatedBy OR @CreatedBy IS NULL)
						
  END
  ELSE
  BEGIN
    SELECT
	  [Id]
	, [Code]
	, [Name]
	, [Type]
	, [ParentId]
	, [CreatedDate]
	, [CreatedBy]
    FROM
	[dbo].[tblNewsCategory]
    WHERE 
	 ([Id] = @Id AND @Id is not null)
	OR ([Code] = @Code AND @Code is not null)
	OR ([Name] = @Name AND @Name is not null)
	OR ([Type] = @Type AND @Type is not null)
	OR ([ParentId] = @ParentId AND @ParentId is not null)
	OR ([CreatedDate] = @CreatedDate AND @CreatedDate is not null)
	OR ([CreatedBy] = @CreatedBy AND @CreatedBy is not null)
	SELECT @@ROWCOUNT			
  END
				

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblNewsLetter_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblNewsLetter_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblNewsLetter_Get_List
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Gets all records from the tblNewsLetter table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblNewsLetter_Get_List

AS


				
				SELECT
					[Id],
					[Email],
					[Note],
					[CustomerName]
				FROM
					[dbo].[tblNewsLetter]
					
				SELECT @@ROWCOUNT
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblNewsLetter_GetPaged procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblNewsLetter_GetPaged') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblNewsLetter_GetPaged
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Gets records from the tblNewsLetter table passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblNewsLetter_GetPaged
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				
				BEGIN
				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				-- Create a temp table to store the select results
				CREATE TABLE #PageIndex
				(
				    [IndexId] int IDENTITY (1, 1) NOT NULL,
				    [Id] int 
				)
				
				-- Insert into the temp table
				DECLARE @SQL AS nvarchar(4000)
				SET @SQL = 'INSERT INTO #PageIndex ([Id])'
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + CONVERT(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' [Id]'
				SET @SQL = @SQL + ' FROM [dbo].[tblNewsLetter]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				IF LEN(@OrderBy) > 0
				BEGIN
					SET @SQL = @SQL + ' ORDER BY ' + @OrderBy
				END
				
				-- Populate the temp table
				EXEC sp_executesql @SQL

				-- Return paged results
				SELECT O.[Id], O.[Email], O.[Note], O.[CustomerName]
				FROM
				    [dbo].[tblNewsLetter] O,
				    #PageIndex PageIndex
				WHERE
				    PageIndex.IndexId > @PageLowerBound
					AND O.[Id] = PageIndex.[Id]
				ORDER BY
				    PageIndex.IndexId
				
				-- get row count
				SET @SQL = 'SELECT COUNT(*) AS TotalRowCount'
				SET @SQL = @SQL + ' FROM [dbo].[tblNewsLetter]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				EXEC sp_executesql @SQL
			
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblNewsLetter_Insert procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblNewsLetter_Insert') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblNewsLetter_Insert
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Inserts a record into the tblNewsLetter table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblNewsLetter_Insert
(

	@Id int    OUTPUT,

	@Email nvarchar (128)  ,

	@Note nvarchar (512)  ,

	@CustomerName nvarchar (128)  
)
AS


				
				INSERT INTO [dbo].[tblNewsLetter]
					(
					[Email]
					,[Note]
					,[CustomerName]
					)
				VALUES
					(
					@Email
					,@Note
					,@CustomerName
					)
				
				-- Get the identity value
				SET @Id = SCOPE_IDENTITY()
									
							
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblNewsLetter_Update procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblNewsLetter_Update') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblNewsLetter_Update
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Updates a record in the tblNewsLetter table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblNewsLetter_Update
(

	@Id int   ,

	@Email nvarchar (128)  ,

	@Note nvarchar (512)  ,

	@CustomerName nvarchar (128)  
)
AS


				
				
				-- Modify the updatable columns
				UPDATE
					[dbo].[tblNewsLetter]
				SET
					[Email] = @Email
					,[Note] = @Note
					,[CustomerName] = @CustomerName
				WHERE
[Id] = @Id 
				
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblNewsLetter_Delete procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblNewsLetter_Delete') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblNewsLetter_Delete
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Deletes a record in the tblNewsLetter table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblNewsLetter_Delete
(

	@Id int   
)
AS


				DELETE FROM [dbo].[tblNewsLetter] WITH (ROWLOCK) 
				WHERE
					[Id] = @Id
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblNewsLetter_GetById procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblNewsLetter_GetById') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblNewsLetter_GetById
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Select records from the tblNewsLetter table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblNewsLetter_GetById
(

	@Id int   
)
AS


				SELECT
					[Id],
					[Email],
					[Note],
					[CustomerName]
				FROM
					[dbo].[tblNewsLetter]
				WHERE
					[Id] = @Id
				SELECT @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblNewsLetter_GetByEmail procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblNewsLetter_GetByEmail') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblNewsLetter_GetByEmail
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Select records from the tblNewsLetter table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblNewsLetter_GetByEmail
(

	@Email nvarchar (128)  
)
AS


				SELECT
					[Id],
					[Email],
					[Note],
					[CustomerName]
				FROM
					[dbo].[tblNewsLetter]
				WHERE
					[Email] = @Email
				SELECT @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblNewsLetter_Find procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblNewsLetter_Find') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblNewsLetter_Find
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Finds records in the tblNewsLetter table passing nullable parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblNewsLetter_Find
(

	@SearchUsingOR bit   = null ,

	@Id int   = null ,

	@Email nvarchar (128)  = null ,

	@Note nvarchar (512)  = null ,

	@CustomerName nvarchar (128)  = null 
)
AS


				
  IF ISNULL(@SearchUsingOR, 0) <> 1
  BEGIN
    SELECT
	  [Id]
	, [Email]
	, [Note]
	, [CustomerName]
    FROM
	[dbo].[tblNewsLetter]
    WHERE 
	 ([Id] = @Id OR @Id IS NULL)
	AND ([Email] = @Email OR @Email IS NULL)
	AND ([Note] = @Note OR @Note IS NULL)
	AND ([CustomerName] = @CustomerName OR @CustomerName IS NULL)
						
  END
  ELSE
  BEGIN
    SELECT
	  [Id]
	, [Email]
	, [Note]
	, [CustomerName]
    FROM
	[dbo].[tblNewsLetter]
    WHERE 
	 ([Id] = @Id AND @Id is not null)
	OR ([Email] = @Email AND @Email is not null)
	OR ([Note] = @Note AND @Note is not null)
	OR ([CustomerName] = @CustomerName AND @CustomerName is not null)
	SELECT @@ROWCOUNT			
  END
				

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblProductLocale_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblProductLocale_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblProductLocale_Get_List
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Gets all records from the tblProductLocale table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblProductLocale_Get_List

AS


				
				SELECT
					[Id],
					[ProductId],
					[LanguageId],
					[Name],
					[RefPrice],
					[Description],
					[Tags],
					[Content],
					[GuarantyPeriod],
					[Material],
					[Original]
				FROM
					[dbo].[tblProductLocale]
					
				SELECT @@ROWCOUNT
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblProductLocale_GetPaged procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblProductLocale_GetPaged') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblProductLocale_GetPaged
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Gets records from the tblProductLocale table passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblProductLocale_GetPaged
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				
				BEGIN
				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				-- Create a temp table to store the select results
				CREATE TABLE #PageIndex
				(
				    [IndexId] int IDENTITY (1, 1) NOT NULL,
				    [Id] int 
				)
				
				-- Insert into the temp table
				DECLARE @SQL AS nvarchar(4000)
				SET @SQL = 'INSERT INTO #PageIndex ([Id])'
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + CONVERT(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' [Id]'
				SET @SQL = @SQL + ' FROM [dbo].[tblProductLocale]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				IF LEN(@OrderBy) > 0
				BEGIN
					SET @SQL = @SQL + ' ORDER BY ' + @OrderBy
				END
				
				-- Populate the temp table
				EXEC sp_executesql @SQL

				-- Return paged results
				SELECT O.[Id], O.[ProductId], O.[LanguageId], O.[Name], O.[RefPrice], O.[Description], O.[Tags], O.[Content], O.[GuarantyPeriod], O.[Material], O.[Original]
				FROM
				    [dbo].[tblProductLocale] O,
				    #PageIndex PageIndex
				WHERE
				    PageIndex.IndexId > @PageLowerBound
					AND O.[Id] = PageIndex.[Id]
				ORDER BY
				    PageIndex.IndexId
				
				-- get row count
				SET @SQL = 'SELECT COUNT(*) AS TotalRowCount'
				SET @SQL = @SQL + ' FROM [dbo].[tblProductLocale]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				EXEC sp_executesql @SQL
			
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblProductLocale_Insert procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblProductLocale_Insert') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblProductLocale_Insert
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Inserts a record into the tblProductLocale table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblProductLocale_Insert
(

	@Id int    OUTPUT,

	@ProductId int   ,

	@LanguageId int   ,

	@Name nvarchar (128)  ,

	@RefPrice decimal (15, 2)  ,

	@Description nvarchar (1024)  ,

	@Tags nvarchar (1024)  ,

	@Content ntext   ,

	@GuarantyPeriod nvarchar (256)  ,

	@Material nvarchar (256)  ,

	@Original nvarchar (256)  
)
AS


				
				INSERT INTO [dbo].[tblProductLocale]
					(
					[ProductId]
					,[LanguageId]
					,[Name]
					,[RefPrice]
					,[Description]
					,[Tags]
					,[Content]
					,[GuarantyPeriod]
					,[Material]
					,[Original]
					)
				VALUES
					(
					@ProductId
					,@LanguageId
					,@Name
					,@RefPrice
					,@Description
					,@Tags
					,@Content
					,@GuarantyPeriod
					,@Material
					,@Original
					)
				
				-- Get the identity value
				SET @Id = SCOPE_IDENTITY()
									
							
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblProductLocale_Update procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblProductLocale_Update') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblProductLocale_Update
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Updates a record in the tblProductLocale table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblProductLocale_Update
(

	@Id int   ,

	@ProductId int   ,

	@LanguageId int   ,

	@Name nvarchar (128)  ,

	@RefPrice decimal (15, 2)  ,

	@Description nvarchar (1024)  ,

	@Tags nvarchar (1024)  ,

	@Content ntext   ,

	@GuarantyPeriod nvarchar (256)  ,

	@Material nvarchar (256)  ,

	@Original nvarchar (256)  
)
AS


				
				
				-- Modify the updatable columns
				UPDATE
					[dbo].[tblProductLocale]
				SET
					[ProductId] = @ProductId
					,[LanguageId] = @LanguageId
					,[Name] = @Name
					,[RefPrice] = @RefPrice
					,[Description] = @Description
					,[Tags] = @Tags
					,[Content] = @Content
					,[GuarantyPeriod] = @GuarantyPeriod
					,[Material] = @Material
					,[Original] = @Original
				WHERE
[Id] = @Id 
				
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblProductLocale_Delete procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblProductLocale_Delete') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblProductLocale_Delete
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Deletes a record in the tblProductLocale table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblProductLocale_Delete
(

	@Id int   
)
AS


				DELETE FROM [dbo].[tblProductLocale] WITH (ROWLOCK) 
				WHERE
					[Id] = @Id
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblProductLocale_GetByProductId procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblProductLocale_GetByProductId') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblProductLocale_GetByProductId
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Select records from the tblProductLocale table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblProductLocale_GetByProductId
(

	@ProductId int   
)
AS


				SET ANSI_NULLS OFF
				
				SELECT
					[Id],
					[ProductId],
					[LanguageId],
					[Name],
					[RefPrice],
					[Description],
					[Tags],
					[Content],
					[GuarantyPeriod],
					[Material],
					[Original]
				FROM
					[dbo].[tblProductLocale]
				WHERE
					[ProductId] = @ProductId
				
				SELECT @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblProductLocale_GetByLanguageId procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblProductLocale_GetByLanguageId') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblProductLocale_GetByLanguageId
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Select records from the tblProductLocale table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblProductLocale_GetByLanguageId
(

	@LanguageId int   
)
AS


				SET ANSI_NULLS OFF
				
				SELECT
					[Id],
					[ProductId],
					[LanguageId],
					[Name],
					[RefPrice],
					[Description],
					[Tags],
					[Content],
					[GuarantyPeriod],
					[Material],
					[Original]
				FROM
					[dbo].[tblProductLocale]
				WHERE
					[LanguageId] = @LanguageId
				
				SELECT @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblProductLocale_GetById procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblProductLocale_GetById') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblProductLocale_GetById
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Select records from the tblProductLocale table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblProductLocale_GetById
(

	@Id int   
)
AS


				SELECT
					[Id],
					[ProductId],
					[LanguageId],
					[Name],
					[RefPrice],
					[Description],
					[Tags],
					[Content],
					[GuarantyPeriod],
					[Material],
					[Original]
				FROM
					[dbo].[tblProductLocale]
				WHERE
					[Id] = @Id
				SELECT @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblProductLocale_Find procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblProductLocale_Find') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblProductLocale_Find
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Finds records in the tblProductLocale table passing nullable parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblProductLocale_Find
(

	@SearchUsingOR bit   = null ,

	@Id int   = null ,

	@ProductId int   = null ,

	@LanguageId int   = null ,

	@Name nvarchar (128)  = null ,

	@RefPrice decimal (15, 2)  = null ,

	@Description nvarchar (1024)  = null ,

	@Tags nvarchar (1024)  = null ,

	@Content ntext   = null ,

	@GuarantyPeriod nvarchar (256)  = null ,

	@Material nvarchar (256)  = null ,

	@Original nvarchar (256)  = null 
)
AS


				
  IF ISNULL(@SearchUsingOR, 0) <> 1
  BEGIN
    SELECT
	  [Id]
	, [ProductId]
	, [LanguageId]
	, [Name]
	, [RefPrice]
	, [Description]
	, [Tags]
	, [Content]
	, [GuarantyPeriod]
	, [Material]
	, [Original]
    FROM
	[dbo].[tblProductLocale]
    WHERE 
	 ([Id] = @Id OR @Id IS NULL)
	AND ([ProductId] = @ProductId OR @ProductId IS NULL)
	AND ([LanguageId] = @LanguageId OR @LanguageId IS NULL)
	AND ([Name] = @Name OR @Name IS NULL)
	AND ([RefPrice] = @RefPrice OR @RefPrice IS NULL)
	AND ([Description] = @Description OR @Description IS NULL)
	AND ([Tags] = @Tags OR @Tags IS NULL)
	AND ([GuarantyPeriod] = @GuarantyPeriod OR @GuarantyPeriod IS NULL)
	AND ([Material] = @Material OR @Material IS NULL)
	AND ([Original] = @Original OR @Original IS NULL)
						
  END
  ELSE
  BEGIN
    SELECT
	  [Id]
	, [ProductId]
	, [LanguageId]
	, [Name]
	, [RefPrice]
	, [Description]
	, [Tags]
	, [Content]
	, [GuarantyPeriod]
	, [Material]
	, [Original]
    FROM
	[dbo].[tblProductLocale]
    WHERE 
	 ([Id] = @Id AND @Id is not null)
	OR ([ProductId] = @ProductId AND @ProductId is not null)
	OR ([LanguageId] = @LanguageId AND @LanguageId is not null)
	OR ([Name] = @Name AND @Name is not null)
	OR ([RefPrice] = @RefPrice AND @RefPrice is not null)
	OR ([Description] = @Description AND @Description is not null)
	OR ([Tags] = @Tags AND @Tags is not null)
	OR ([GuarantyPeriod] = @GuarantyPeriod AND @GuarantyPeriod is not null)
	OR ([Material] = @Material AND @Material is not null)
	OR ([Original] = @Original AND @Original is not null)
	SELECT @@ROWCOUNT			
  END
				

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblNewsCategoryLocale_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblNewsCategoryLocale_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblNewsCategoryLocale_Get_List
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Gets all records from the tblNewsCategoryLocale table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblNewsCategoryLocale_Get_List

AS


				
				SELECT
					[Id],
					[NewsCategoryId],
					[LanguageId],
					[Name],
					[Description]
				FROM
					[dbo].[tblNewsCategoryLocale]
					
				SELECT @@ROWCOUNT
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblNewsCategoryLocale_GetPaged procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblNewsCategoryLocale_GetPaged') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblNewsCategoryLocale_GetPaged
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Gets records from the tblNewsCategoryLocale table passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblNewsCategoryLocale_GetPaged
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				
				BEGIN
				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				-- Create a temp table to store the select results
				CREATE TABLE #PageIndex
				(
				    [IndexId] int IDENTITY (1, 1) NOT NULL,
				    [Id] int 
				)
				
				-- Insert into the temp table
				DECLARE @SQL AS nvarchar(4000)
				SET @SQL = 'INSERT INTO #PageIndex ([Id])'
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + CONVERT(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' [Id]'
				SET @SQL = @SQL + ' FROM [dbo].[tblNewsCategoryLocale]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				IF LEN(@OrderBy) > 0
				BEGIN
					SET @SQL = @SQL + ' ORDER BY ' + @OrderBy
				END
				
				-- Populate the temp table
				EXEC sp_executesql @SQL

				-- Return paged results
				SELECT O.[Id], O.[NewsCategoryId], O.[LanguageId], O.[Name], O.[Description]
				FROM
				    [dbo].[tblNewsCategoryLocale] O,
				    #PageIndex PageIndex
				WHERE
				    PageIndex.IndexId > @PageLowerBound
					AND O.[Id] = PageIndex.[Id]
				ORDER BY
				    PageIndex.IndexId
				
				-- get row count
				SET @SQL = 'SELECT COUNT(*) AS TotalRowCount'
				SET @SQL = @SQL + ' FROM [dbo].[tblNewsCategoryLocale]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				EXEC sp_executesql @SQL
			
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblNewsCategoryLocale_Insert procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblNewsCategoryLocale_Insert') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblNewsCategoryLocale_Insert
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Inserts a record into the tblNewsCategoryLocale table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblNewsCategoryLocale_Insert
(

	@Id int    OUTPUT,

	@NewsCategoryId int   ,

	@LanguageId int   ,

	@Name nvarchar (256)  ,

	@Description nvarchar (1024)  
)
AS


				
				INSERT INTO [dbo].[tblNewsCategoryLocale]
					(
					[NewsCategoryId]
					,[LanguageId]
					,[Name]
					,[Description]
					)
				VALUES
					(
					@NewsCategoryId
					,@LanguageId
					,@Name
					,@Description
					)
				
				-- Get the identity value
				SET @Id = SCOPE_IDENTITY()
									
							
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblNewsCategoryLocale_Update procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblNewsCategoryLocale_Update') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblNewsCategoryLocale_Update
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Updates a record in the tblNewsCategoryLocale table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblNewsCategoryLocale_Update
(

	@Id int   ,

	@NewsCategoryId int   ,

	@LanguageId int   ,

	@Name nvarchar (256)  ,

	@Description nvarchar (1024)  
)
AS


				
				
				-- Modify the updatable columns
				UPDATE
					[dbo].[tblNewsCategoryLocale]
				SET
					[NewsCategoryId] = @NewsCategoryId
					,[LanguageId] = @LanguageId
					,[Name] = @Name
					,[Description] = @Description
				WHERE
[Id] = @Id 
				
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblNewsCategoryLocale_Delete procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblNewsCategoryLocale_Delete') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblNewsCategoryLocale_Delete
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Deletes a record in the tblNewsCategoryLocale table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblNewsCategoryLocale_Delete
(

	@Id int   
)
AS


				DELETE FROM [dbo].[tblNewsCategoryLocale] WITH (ROWLOCK) 
				WHERE
					[Id] = @Id
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblNewsCategoryLocale_GetByNewsCategoryId procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblNewsCategoryLocale_GetByNewsCategoryId') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblNewsCategoryLocale_GetByNewsCategoryId
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Select records from the tblNewsCategoryLocale table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblNewsCategoryLocale_GetByNewsCategoryId
(

	@NewsCategoryId int   
)
AS


				SET ANSI_NULLS OFF
				
				SELECT
					[Id],
					[NewsCategoryId],
					[LanguageId],
					[Name],
					[Description]
				FROM
					[dbo].[tblNewsCategoryLocale]
				WHERE
					[NewsCategoryId] = @NewsCategoryId
				
				SELECT @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblNewsCategoryLocale_GetByLanguageId procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblNewsCategoryLocale_GetByLanguageId') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblNewsCategoryLocale_GetByLanguageId
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Select records from the tblNewsCategoryLocale table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblNewsCategoryLocale_GetByLanguageId
(

	@LanguageId int   
)
AS


				SET ANSI_NULLS OFF
				
				SELECT
					[Id],
					[NewsCategoryId],
					[LanguageId],
					[Name],
					[Description]
				FROM
					[dbo].[tblNewsCategoryLocale]
				WHERE
					[LanguageId] = @LanguageId
				
				SELECT @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblNewsCategoryLocale_GetById procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblNewsCategoryLocale_GetById') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblNewsCategoryLocale_GetById
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Select records from the tblNewsCategoryLocale table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblNewsCategoryLocale_GetById
(

	@Id int   
)
AS


				SELECT
					[Id],
					[NewsCategoryId],
					[LanguageId],
					[Name],
					[Description]
				FROM
					[dbo].[tblNewsCategoryLocale]
				WHERE
					[Id] = @Id
				SELECT @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblNewsCategoryLocale_Find procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblNewsCategoryLocale_Find') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblNewsCategoryLocale_Find
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Finds records in the tblNewsCategoryLocale table passing nullable parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblNewsCategoryLocale_Find
(

	@SearchUsingOR bit   = null ,

	@Id int   = null ,

	@NewsCategoryId int   = null ,

	@LanguageId int   = null ,

	@Name nvarchar (256)  = null ,

	@Description nvarchar (1024)  = null 
)
AS


				
  IF ISNULL(@SearchUsingOR, 0) <> 1
  BEGIN
    SELECT
	  [Id]
	, [NewsCategoryId]
	, [LanguageId]
	, [Name]
	, [Description]
    FROM
	[dbo].[tblNewsCategoryLocale]
    WHERE 
	 ([Id] = @Id OR @Id IS NULL)
	AND ([NewsCategoryId] = @NewsCategoryId OR @NewsCategoryId IS NULL)
	AND ([LanguageId] = @LanguageId OR @LanguageId IS NULL)
	AND ([Name] = @Name OR @Name IS NULL)
	AND ([Description] = @Description OR @Description IS NULL)
						
  END
  ELSE
  BEGIN
    SELECT
	  [Id]
	, [NewsCategoryId]
	, [LanguageId]
	, [Name]
	, [Description]
    FROM
	[dbo].[tblNewsCategoryLocale]
    WHERE 
	 ([Id] = @Id AND @Id is not null)
	OR ([NewsCategoryId] = @NewsCategoryId AND @NewsCategoryId is not null)
	OR ([LanguageId] = @LanguageId AND @LanguageId is not null)
	OR ([Name] = @Name AND @Name is not null)
	OR ([Description] = @Description AND @Description is not null)
	SELECT @@ROWCOUNT			
  END
				

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblAlbum_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblAlbum_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblAlbum_Get_List
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Gets all records from the tblAlbum table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblAlbum_Get_List

AS


				
				SELECT
					[Id],
					[Name],
					[Type],
					[Status],
					[CreatedDate],
					[CreatedBy],
					[ModifiedDate],
					[ModifiedBy],
					[ShowOnHome]
				FROM
					[dbo].[tblAlbum]
					
				SELECT @@ROWCOUNT
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblAlbum_GetPaged procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblAlbum_GetPaged') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblAlbum_GetPaged
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Gets records from the tblAlbum table passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblAlbum_GetPaged
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				
				BEGIN
				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				-- Create a temp table to store the select results
				CREATE TABLE #PageIndex
				(
				    [IndexId] int IDENTITY (1, 1) NOT NULL,
				    [Id] int 
				)
				
				-- Insert into the temp table
				DECLARE @SQL AS nvarchar(4000)
				SET @SQL = 'INSERT INTO #PageIndex ([Id])'
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + CONVERT(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' [Id]'
				SET @SQL = @SQL + ' FROM [dbo].[tblAlbum]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				IF LEN(@OrderBy) > 0
				BEGIN
					SET @SQL = @SQL + ' ORDER BY ' + @OrderBy
				END
				
				-- Populate the temp table
				EXEC sp_executesql @SQL

				-- Return paged results
				SELECT O.[Id], O.[Name], O.[Type], O.[Status], O.[CreatedDate], O.[CreatedBy], O.[ModifiedDate], O.[ModifiedBy], O.[ShowOnHome]
				FROM
				    [dbo].[tblAlbum] O,
				    #PageIndex PageIndex
				WHERE
				    PageIndex.IndexId > @PageLowerBound
					AND O.[Id] = PageIndex.[Id]
				ORDER BY
				    PageIndex.IndexId
				
				-- get row count
				SET @SQL = 'SELECT COUNT(*) AS TotalRowCount'
				SET @SQL = @SQL + ' FROM [dbo].[tblAlbum]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				EXEC sp_executesql @SQL
			
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblAlbum_Insert procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblAlbum_Insert') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblAlbum_Insert
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Inserts a record into the tblAlbum table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblAlbum_Insert
(

	@Id int    OUTPUT,

	@Name nvarchar (128)  ,

	@Type char (1)  ,

	@Status char (1)  ,

	@CreatedDate datetime   ,

	@CreatedBy varchar (50)  ,

	@ModifiedDate datetime   ,

	@ModifiedBy varchar (50)  ,

	@ShowOnHome bit   
)
AS


				
				INSERT INTO [dbo].[tblAlbum]
					(
					[Name]
					,[Type]
					,[Status]
					,[CreatedDate]
					,[CreatedBy]
					,[ModifiedDate]
					,[ModifiedBy]
					,[ShowOnHome]
					)
				VALUES
					(
					@Name
					,@Type
					,@Status
					,@CreatedDate
					,@CreatedBy
					,@ModifiedDate
					,@ModifiedBy
					,@ShowOnHome
					)
				
				-- Get the identity value
				SET @Id = SCOPE_IDENTITY()
									
							
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblAlbum_Update procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblAlbum_Update') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblAlbum_Update
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Updates a record in the tblAlbum table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblAlbum_Update
(

	@Id int   ,

	@Name nvarchar (128)  ,

	@Type char (1)  ,

	@Status char (1)  ,

	@CreatedDate datetime   ,

	@CreatedBy varchar (50)  ,

	@ModifiedDate datetime   ,

	@ModifiedBy varchar (50)  ,

	@ShowOnHome bit   
)
AS


				
				
				-- Modify the updatable columns
				UPDATE
					[dbo].[tblAlbum]
				SET
					[Name] = @Name
					,[Type] = @Type
					,[Status] = @Status
					,[CreatedDate] = @CreatedDate
					,[CreatedBy] = @CreatedBy
					,[ModifiedDate] = @ModifiedDate
					,[ModifiedBy] = @ModifiedBy
					,[ShowOnHome] = @ShowOnHome
				WHERE
[Id] = @Id 
				
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblAlbum_Delete procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblAlbum_Delete') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblAlbum_Delete
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Deletes a record in the tblAlbum table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblAlbum_Delete
(

	@Id int   
)
AS


				DELETE FROM [dbo].[tblAlbum] WITH (ROWLOCK) 
				WHERE
					[Id] = @Id
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblAlbum_GetById procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblAlbum_GetById') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblAlbum_GetById
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Select records from the tblAlbum table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblAlbum_GetById
(

	@Id int   
)
AS


				SELECT
					[Id],
					[Name],
					[Type],
					[Status],
					[CreatedDate],
					[CreatedBy],
					[ModifiedDate],
					[ModifiedBy],
					[ShowOnHome]
				FROM
					[dbo].[tblAlbum]
				WHERE
					[Id] = @Id
				SELECT @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblAlbum_Find procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblAlbum_Find') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblAlbum_Find
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Finds records in the tblAlbum table passing nullable parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblAlbum_Find
(

	@SearchUsingOR bit   = null ,

	@Id int   = null ,

	@Name nvarchar (128)  = null ,

	@Type char (1)  = null ,

	@Status char (1)  = null ,

	@CreatedDate datetime   = null ,

	@CreatedBy varchar (50)  = null ,

	@ModifiedDate datetime   = null ,

	@ModifiedBy varchar (50)  = null ,

	@ShowOnHome bit   = null 
)
AS


				
  IF ISNULL(@SearchUsingOR, 0) <> 1
  BEGIN
    SELECT
	  [Id]
	, [Name]
	, [Type]
	, [Status]
	, [CreatedDate]
	, [CreatedBy]
	, [ModifiedDate]
	, [ModifiedBy]
	, [ShowOnHome]
    FROM
	[dbo].[tblAlbum]
    WHERE 
	 ([Id] = @Id OR @Id IS NULL)
	AND ([Name] = @Name OR @Name IS NULL)
	AND ([Type] = @Type OR @Type IS NULL)
	AND ([Status] = @Status OR @Status IS NULL)
	AND ([CreatedDate] = @CreatedDate OR @CreatedDate IS NULL)
	AND ([CreatedBy] = @CreatedBy OR @CreatedBy IS NULL)
	AND ([ModifiedDate] = @ModifiedDate OR @ModifiedDate IS NULL)
	AND ([ModifiedBy] = @ModifiedBy OR @ModifiedBy IS NULL)
	AND ([ShowOnHome] = @ShowOnHome OR @ShowOnHome IS NULL)
						
  END
  ELSE
  BEGIN
    SELECT
	  [Id]
	, [Name]
	, [Type]
	, [Status]
	, [CreatedDate]
	, [CreatedBy]
	, [ModifiedDate]
	, [ModifiedBy]
	, [ShowOnHome]
    FROM
	[dbo].[tblAlbum]
    WHERE 
	 ([Id] = @Id AND @Id is not null)
	OR ([Name] = @Name AND @Name is not null)
	OR ([Type] = @Type AND @Type is not null)
	OR ([Status] = @Status AND @Status is not null)
	OR ([CreatedDate] = @CreatedDate AND @CreatedDate is not null)
	OR ([CreatedBy] = @CreatedBy AND @CreatedBy is not null)
	OR ([ModifiedDate] = @ModifiedDate AND @ModifiedDate is not null)
	OR ([ModifiedBy] = @ModifiedBy AND @ModifiedBy is not null)
	OR ([ShowOnHome] = @ShowOnHome AND @ShowOnHome is not null)
	SELECT @@ROWCOUNT			
  END
				

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblSetting_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblSetting_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblSetting_Get_List
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Gets all records from the tblSetting table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblSetting_Get_List

AS


				
				SELECT
					[Id],
					[Name],
					[Value],
					[Description]
				FROM
					[dbo].[tblSetting]
					
				SELECT @@ROWCOUNT
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblSetting_GetPaged procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblSetting_GetPaged') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblSetting_GetPaged
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Gets records from the tblSetting table passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblSetting_GetPaged
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				
				BEGIN
				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				-- Create a temp table to store the select results
				CREATE TABLE #PageIndex
				(
				    [IndexId] int IDENTITY (1, 1) NOT NULL,
				    [Id] int 
				)
				
				-- Insert into the temp table
				DECLARE @SQL AS nvarchar(4000)
				SET @SQL = 'INSERT INTO #PageIndex ([Id])'
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + CONVERT(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' [Id]'
				SET @SQL = @SQL + ' FROM [dbo].[tblSetting]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				IF LEN(@OrderBy) > 0
				BEGIN
					SET @SQL = @SQL + ' ORDER BY ' + @OrderBy
				END
				
				-- Populate the temp table
				EXEC sp_executesql @SQL

				-- Return paged results
				SELECT O.[Id], O.[Name], O.[Value], O.[Description]
				FROM
				    [dbo].[tblSetting] O,
				    #PageIndex PageIndex
				WHERE
				    PageIndex.IndexId > @PageLowerBound
					AND O.[Id] = PageIndex.[Id]
				ORDER BY
				    PageIndex.IndexId
				
				-- get row count
				SET @SQL = 'SELECT COUNT(*) AS TotalRowCount'
				SET @SQL = @SQL + ' FROM [dbo].[tblSetting]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				EXEC sp_executesql @SQL
			
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblSetting_Insert procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblSetting_Insert') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblSetting_Insert
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Inserts a record into the tblSetting table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblSetting_Insert
(

	@Id int    OUTPUT,

	@Name varchar (50)  ,

	@Value nvarchar (128)  ,

	@Description nvarchar (128)  
)
AS


				
				INSERT INTO [dbo].[tblSetting]
					(
					[Name]
					,[Value]
					,[Description]
					)
				VALUES
					(
					@Name
					,@Value
					,@Description
					)
				
				-- Get the identity value
				SET @Id = SCOPE_IDENTITY()
									
							
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblSetting_Update procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblSetting_Update') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblSetting_Update
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Updates a record in the tblSetting table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblSetting_Update
(

	@Id int   ,

	@Name varchar (50)  ,

	@Value nvarchar (128)  ,

	@Description nvarchar (128)  
)
AS


				
				
				-- Modify the updatable columns
				UPDATE
					[dbo].[tblSetting]
				SET
					[Name] = @Name
					,[Value] = @Value
					,[Description] = @Description
				WHERE
[Id] = @Id 
				
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblSetting_Delete procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblSetting_Delete') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblSetting_Delete
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Deletes a record in the tblSetting table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblSetting_Delete
(

	@Id int   
)
AS


				DELETE FROM [dbo].[tblSetting] WITH (ROWLOCK) 
				WHERE
					[Id] = @Id
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblSetting_GetById procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblSetting_GetById') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblSetting_GetById
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Select records from the tblSetting table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblSetting_GetById
(

	@Id int   
)
AS


				SELECT
					[Id],
					[Name],
					[Value],
					[Description]
				FROM
					[dbo].[tblSetting]
				WHERE
					[Id] = @Id
				SELECT @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblSetting_GetByName procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblSetting_GetByName') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblSetting_GetByName
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Select records from the tblSetting table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblSetting_GetByName
(

	@Name varchar (50)  
)
AS


				SELECT
					[Id],
					[Name],
					[Value],
					[Description]
				FROM
					[dbo].[tblSetting]
				WHERE
					[Name] = @Name
				SELECT @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblSetting_Find procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblSetting_Find') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblSetting_Find
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Finds records in the tblSetting table passing nullable parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblSetting_Find
(

	@SearchUsingOR bit   = null ,

	@Id int   = null ,

	@Name varchar (50)  = null ,

	@Value nvarchar (128)  = null ,

	@Description nvarchar (128)  = null 
)
AS


				
  IF ISNULL(@SearchUsingOR, 0) <> 1
  BEGIN
    SELECT
	  [Id]
	, [Name]
	, [Value]
	, [Description]
    FROM
	[dbo].[tblSetting]
    WHERE 
	 ([Id] = @Id OR @Id IS NULL)
	AND ([Name] = @Name OR @Name IS NULL)
	AND ([Value] = @Value OR @Value IS NULL)
	AND ([Description] = @Description OR @Description IS NULL)
						
  END
  ELSE
  BEGIN
    SELECT
	  [Id]
	, [Name]
	, [Value]
	, [Description]
    FROM
	[dbo].[tblSetting]
    WHERE 
	 ([Id] = @Id AND @Id is not null)
	OR ([Name] = @Name AND @Name is not null)
	OR ([Value] = @Value AND @Value is not null)
	OR ([Description] = @Description AND @Description is not null)
	SELECT @@ROWCOUNT			
  END
				

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblSurvey_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblSurvey_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblSurvey_Get_List
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Gets all records from the tblSurvey table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblSurvey_Get_List

AS


				
				SELECT
					[Id],
					[CreatedDate],
					[CreatedBy],
					[Note],
					[Type],
					[IsActive],
					[Question],
					[LanguageId]
				FROM
					[dbo].[tblSurvey]
					
				SELECT @@ROWCOUNT
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblSurvey_GetPaged procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblSurvey_GetPaged') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblSurvey_GetPaged
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Gets records from the tblSurvey table passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblSurvey_GetPaged
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				
				BEGIN
				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				-- Create a temp table to store the select results
				CREATE TABLE #PageIndex
				(
				    [IndexId] int IDENTITY (1, 1) NOT NULL,
				    [Id] int 
				)
				
				-- Insert into the temp table
				DECLARE @SQL AS nvarchar(4000)
				SET @SQL = 'INSERT INTO #PageIndex ([Id])'
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + CONVERT(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' [Id]'
				SET @SQL = @SQL + ' FROM [dbo].[tblSurvey]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				IF LEN(@OrderBy) > 0
				BEGIN
					SET @SQL = @SQL + ' ORDER BY ' + @OrderBy
				END
				
				-- Populate the temp table
				EXEC sp_executesql @SQL

				-- Return paged results
				SELECT O.[Id], O.[CreatedDate], O.[CreatedBy], O.[Note], O.[Type], O.[IsActive], O.[Question], O.[LanguageId]
				FROM
				    [dbo].[tblSurvey] O,
				    #PageIndex PageIndex
				WHERE
				    PageIndex.IndexId > @PageLowerBound
					AND O.[Id] = PageIndex.[Id]
				ORDER BY
				    PageIndex.IndexId
				
				-- get row count
				SET @SQL = 'SELECT COUNT(*) AS TotalRowCount'
				SET @SQL = @SQL + ' FROM [dbo].[tblSurvey]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				EXEC sp_executesql @SQL
			
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblSurvey_Insert procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblSurvey_Insert') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblSurvey_Insert
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Inserts a record into the tblSurvey table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblSurvey_Insert
(

	@Id int    OUTPUT,

	@CreatedDate datetime   ,

	@CreatedBy nvarchar (128)  ,

	@Note nvarchar (512)  ,

	@Type char (1)  ,

	@IsActive bit   ,

	@Question nvarchar (512)  ,

	@LanguageId int   
)
AS


				
				INSERT INTO [dbo].[tblSurvey]
					(
					[CreatedDate]
					,[CreatedBy]
					,[Note]
					,[Type]
					,[IsActive]
					,[Question]
					,[LanguageId]
					)
				VALUES
					(
					@CreatedDate
					,@CreatedBy
					,@Note
					,@Type
					,@IsActive
					,@Question
					,@LanguageId
					)
				
				-- Get the identity value
				SET @Id = SCOPE_IDENTITY()
									
							
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblSurvey_Update procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblSurvey_Update') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblSurvey_Update
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Updates a record in the tblSurvey table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblSurvey_Update
(

	@Id int   ,

	@CreatedDate datetime   ,

	@CreatedBy nvarchar (128)  ,

	@Note nvarchar (512)  ,

	@Type char (1)  ,

	@IsActive bit   ,

	@Question nvarchar (512)  ,

	@LanguageId int   
)
AS


				
				
				-- Modify the updatable columns
				UPDATE
					[dbo].[tblSurvey]
				SET
					[CreatedDate] = @CreatedDate
					,[CreatedBy] = @CreatedBy
					,[Note] = @Note
					,[Type] = @Type
					,[IsActive] = @IsActive
					,[Question] = @Question
					,[LanguageId] = @LanguageId
				WHERE
[Id] = @Id 
				
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblSurvey_Delete procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblSurvey_Delete') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblSurvey_Delete
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Deletes a record in the tblSurvey table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblSurvey_Delete
(

	@Id int   
)
AS


				DELETE FROM [dbo].[tblSurvey] WITH (ROWLOCK) 
				WHERE
					[Id] = @Id
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblSurvey_GetByLanguageId procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblSurvey_GetByLanguageId') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblSurvey_GetByLanguageId
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Select records from the tblSurvey table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblSurvey_GetByLanguageId
(

	@LanguageId int   
)
AS


				SET ANSI_NULLS OFF
				
				SELECT
					[Id],
					[CreatedDate],
					[CreatedBy],
					[Note],
					[Type],
					[IsActive],
					[Question],
					[LanguageId]
				FROM
					[dbo].[tblSurvey]
				WHERE
					[LanguageId] = @LanguageId
				
				SELECT @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblSurvey_GetById procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblSurvey_GetById') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblSurvey_GetById
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Select records from the tblSurvey table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblSurvey_GetById
(

	@Id int   
)
AS


				SELECT
					[Id],
					[CreatedDate],
					[CreatedBy],
					[Note],
					[Type],
					[IsActive],
					[Question],
					[LanguageId]
				FROM
					[dbo].[tblSurvey]
				WHERE
					[Id] = @Id
				SELECT @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblSurvey_Find procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblSurvey_Find') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblSurvey_Find
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Finds records in the tblSurvey table passing nullable parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblSurvey_Find
(

	@SearchUsingOR bit   = null ,

	@Id int   = null ,

	@CreatedDate datetime   = null ,

	@CreatedBy nvarchar (128)  = null ,

	@Note nvarchar (512)  = null ,

	@Type char (1)  = null ,

	@IsActive bit   = null ,

	@Question nvarchar (512)  = null ,

	@LanguageId int   = null 
)
AS


				
  IF ISNULL(@SearchUsingOR, 0) <> 1
  BEGIN
    SELECT
	  [Id]
	, [CreatedDate]
	, [CreatedBy]
	, [Note]
	, [Type]
	, [IsActive]
	, [Question]
	, [LanguageId]
    FROM
	[dbo].[tblSurvey]
    WHERE 
	 ([Id] = @Id OR @Id IS NULL)
	AND ([CreatedDate] = @CreatedDate OR @CreatedDate IS NULL)
	AND ([CreatedBy] = @CreatedBy OR @CreatedBy IS NULL)
	AND ([Note] = @Note OR @Note IS NULL)
	AND ([Type] = @Type OR @Type IS NULL)
	AND ([IsActive] = @IsActive OR @IsActive IS NULL)
	AND ([Question] = @Question OR @Question IS NULL)
	AND ([LanguageId] = @LanguageId OR @LanguageId IS NULL)
						
  END
  ELSE
  BEGIN
    SELECT
	  [Id]
	, [CreatedDate]
	, [CreatedBy]
	, [Note]
	, [Type]
	, [IsActive]
	, [Question]
	, [LanguageId]
    FROM
	[dbo].[tblSurvey]
    WHERE 
	 ([Id] = @Id AND @Id is not null)
	OR ([CreatedDate] = @CreatedDate AND @CreatedDate is not null)
	OR ([CreatedBy] = @CreatedBy AND @CreatedBy is not null)
	OR ([Note] = @Note AND @Note is not null)
	OR ([Type] = @Type AND @Type is not null)
	OR ([IsActive] = @IsActive AND @IsActive is not null)
	OR ([Question] = @Question AND @Question is not null)
	OR ([LanguageId] = @LanguageId AND @LanguageId is not null)
	SELECT @@ROWCOUNT			
  END
				

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblUser_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblUser_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblUser_Get_List
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Gets all records from the tblUser table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblUser_Get_List

AS


				
				SELECT
					[Username],
					[Password],
					[Status],
					[Fullname],
					[Phone],
					[Email],
					[Address],
					[CreatedBy],
					[CreatedDate]
				FROM
					[dbo].[tblUser]
					
				SELECT @@ROWCOUNT
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblUser_GetPaged procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblUser_GetPaged') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblUser_GetPaged
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Gets records from the tblUser table passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblUser_GetPaged
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				
				BEGIN
				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				-- Create a temp table to store the select results
				CREATE TABLE #PageIndex
				(
				    [IndexId] int IDENTITY (1, 1) NOT NULL,
				    [Username] varchar(50) COLLATE database_default  
				)
				
				-- Insert into the temp table
				DECLARE @SQL AS nvarchar(4000)
				SET @SQL = 'INSERT INTO #PageIndex ([Username])'
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + CONVERT(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' [Username]'
				SET @SQL = @SQL + ' FROM [dbo].[tblUser]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				IF LEN(@OrderBy) > 0
				BEGIN
					SET @SQL = @SQL + ' ORDER BY ' + @OrderBy
				END
				
				-- Populate the temp table
				EXEC sp_executesql @SQL

				-- Return paged results
				SELECT O.[Username], O.[Password], O.[Status], O.[Fullname], O.[Phone], O.[Email], O.[Address], O.[CreatedBy], O.[CreatedDate]
				FROM
				    [dbo].[tblUser] O,
				    #PageIndex PageIndex
				WHERE
				    PageIndex.IndexId > @PageLowerBound
					AND O.[Username] = PageIndex.[Username]
				ORDER BY
				    PageIndex.IndexId
				
				-- get row count
				SET @SQL = 'SELECT COUNT(*) AS TotalRowCount'
				SET @SQL = @SQL + ' FROM [dbo].[tblUser]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				EXEC sp_executesql @SQL
			
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblUser_Insert procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblUser_Insert') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblUser_Insert
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Inserts a record into the tblUser table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblUser_Insert
(

	@Username varchar (50)  ,

	@Password varchar (50)  ,

	@Status char (1)  ,

	@Fullname nvarchar (256)  ,

	@Phone varchar (32)  ,

	@Email varchar (50)  ,

	@Address nvarchar (256)  ,

	@CreatedBy varchar (50)  ,

	@CreatedDate datetime   
)
AS


				
				INSERT INTO [dbo].[tblUser]
					(
					[Username]
					,[Password]
					,[Status]
					,[Fullname]
					,[Phone]
					,[Email]
					,[Address]
					,[CreatedBy]
					,[CreatedDate]
					)
				VALUES
					(
					@Username
					,@Password
					,@Status
					,@Fullname
					,@Phone
					,@Email
					,@Address
					,@CreatedBy
					,@CreatedDate
					)
				
									
							
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblUser_Update procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblUser_Update') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblUser_Update
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Updates a record in the tblUser table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblUser_Update
(

	@Username varchar (50)  ,

	@OriginalUsername varchar (50)  ,

	@Password varchar (50)  ,

	@Status char (1)  ,

	@Fullname nvarchar (256)  ,

	@Phone varchar (32)  ,

	@Email varchar (50)  ,

	@Address nvarchar (256)  ,

	@CreatedBy varchar (50)  ,

	@CreatedDate datetime   
)
AS


				
				
				-- Modify the updatable columns
				UPDATE
					[dbo].[tblUser]
				SET
					[Username] = @Username
					,[Password] = @Password
					,[Status] = @Status
					,[Fullname] = @Fullname
					,[Phone] = @Phone
					,[Email] = @Email
					,[Address] = @Address
					,[CreatedBy] = @CreatedBy
					,[CreatedDate] = @CreatedDate
				WHERE
[Username] = @OriginalUsername 
				
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblUser_Delete procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblUser_Delete') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblUser_Delete
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Deletes a record in the tblUser table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblUser_Delete
(

	@Username varchar (50)  
)
AS


				DELETE FROM [dbo].[tblUser] WITH (ROWLOCK) 
				WHERE
					[Username] = @Username
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblUser_GetByUsername procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblUser_GetByUsername') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblUser_GetByUsername
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Select records from the tblUser table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblUser_GetByUsername
(

	@Username varchar (50)  
)
AS


				SELECT
					[Username],
					[Password],
					[Status],
					[Fullname],
					[Phone],
					[Email],
					[Address],
					[CreatedBy],
					[CreatedDate]
				FROM
					[dbo].[tblUser]
				WHERE
					[Username] = @Username
				SELECT @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblUser_Find procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblUser_Find') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblUser_Find
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Finds records in the tblUser table passing nullable parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblUser_Find
(

	@SearchUsingOR bit   = null ,

	@Username varchar (50)  = null ,

	@Password varchar (50)  = null ,

	@Status char (1)  = null ,

	@Fullname nvarchar (256)  = null ,

	@Phone varchar (32)  = null ,

	@Email varchar (50)  = null ,

	@Address nvarchar (256)  = null ,

	@CreatedBy varchar (50)  = null ,

	@CreatedDate datetime   = null 
)
AS


				
  IF ISNULL(@SearchUsingOR, 0) <> 1
  BEGIN
    SELECT
	  [Username]
	, [Password]
	, [Status]
	, [Fullname]
	, [Phone]
	, [Email]
	, [Address]
	, [CreatedBy]
	, [CreatedDate]
    FROM
	[dbo].[tblUser]
    WHERE 
	 ([Username] = @Username OR @Username IS NULL)
	AND ([Password] = @Password OR @Password IS NULL)
	AND ([Status] = @Status OR @Status IS NULL)
	AND ([Fullname] = @Fullname OR @Fullname IS NULL)
	AND ([Phone] = @Phone OR @Phone IS NULL)
	AND ([Email] = @Email OR @Email IS NULL)
	AND ([Address] = @Address OR @Address IS NULL)
	AND ([CreatedBy] = @CreatedBy OR @CreatedBy IS NULL)
	AND ([CreatedDate] = @CreatedDate OR @CreatedDate IS NULL)
						
  END
  ELSE
  BEGIN
    SELECT
	  [Username]
	, [Password]
	, [Status]
	, [Fullname]
	, [Phone]
	, [Email]
	, [Address]
	, [CreatedBy]
	, [CreatedDate]
    FROM
	[dbo].[tblUser]
    WHERE 
	 ([Username] = @Username AND @Username is not null)
	OR ([Password] = @Password AND @Password is not null)
	OR ([Status] = @Status AND @Status is not null)
	OR ([Fullname] = @Fullname AND @Fullname is not null)
	OR ([Phone] = @Phone AND @Phone is not null)
	OR ([Email] = @Email AND @Email is not null)
	OR ([Address] = @Address AND @Address is not null)
	OR ([CreatedBy] = @CreatedBy AND @CreatedBy is not null)
	OR ([CreatedDate] = @CreatedDate AND @CreatedDate is not null)
	SELECT @@ROWCOUNT			
  END
				

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblSubMenu_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblSubMenu_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblSubMenu_Get_List
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Gets all records from the tblSubMenu table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblSubMenu_Get_List

AS


				
				SELECT
					[Id],
					[Code],
					[Name],
					[Link],
					[MainMenuId],
					[ParentId],
					[FunctionId],
					[Order],
					[LayoutPosition]
				FROM
					[dbo].[tblSubMenu]
					
				SELECT @@ROWCOUNT
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblSubMenu_GetPaged procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblSubMenu_GetPaged') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblSubMenu_GetPaged
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Gets records from the tblSubMenu table passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblSubMenu_GetPaged
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				
				BEGIN
				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				-- Create a temp table to store the select results
				CREATE TABLE #PageIndex
				(
				    [IndexId] int IDENTITY (1, 1) NOT NULL,
				    [Id] int 
				)
				
				-- Insert into the temp table
				DECLARE @SQL AS nvarchar(4000)
				SET @SQL = 'INSERT INTO #PageIndex ([Id])'
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + CONVERT(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' [Id]'
				SET @SQL = @SQL + ' FROM [dbo].[tblSubMenu]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				IF LEN(@OrderBy) > 0
				BEGIN
					SET @SQL = @SQL + ' ORDER BY ' + @OrderBy
				END
				
				-- Populate the temp table
				EXEC sp_executesql @SQL

				-- Return paged results
				SELECT O.[Id], O.[Code], O.[Name], O.[Link], O.[MainMenuId], O.[ParentId], O.[FunctionId], O.[Order], O.[LayoutPosition]
				FROM
				    [dbo].[tblSubMenu] O,
				    #PageIndex PageIndex
				WHERE
				    PageIndex.IndexId > @PageLowerBound
					AND O.[Id] = PageIndex.[Id]
				ORDER BY
				    PageIndex.IndexId
				
				-- get row count
				SET @SQL = 'SELECT COUNT(*) AS TotalRowCount'
				SET @SQL = @SQL + ' FROM [dbo].[tblSubMenu]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				EXEC sp_executesql @SQL
			
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblSubMenu_Insert procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblSubMenu_Insert') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblSubMenu_Insert
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Inserts a record into the tblSubMenu table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblSubMenu_Insert
(

	@Id int    OUTPUT,

	@Code varchar (50)  ,

	@Name nvarchar (128)  ,

	@Link nvarchar (512)  ,

	@MainMenuId int   ,

	@ParentId int   ,

	@FunctionId bigint   ,

	@Order int   ,

	@LayoutPosition int   
)
AS


				
				INSERT INTO [dbo].[tblSubMenu]
					(
					[Code]
					,[Name]
					,[Link]
					,[MainMenuId]
					,[ParentId]
					,[FunctionId]
					,[Order]
					,[LayoutPosition]
					)
				VALUES
					(
					@Code
					,@Name
					,@Link
					,@MainMenuId
					,@ParentId
					,@FunctionId
					,@Order
					,@LayoutPosition
					)
				
				-- Get the identity value
				SET @Id = SCOPE_IDENTITY()
									
							
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblSubMenu_Update procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblSubMenu_Update') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblSubMenu_Update
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Updates a record in the tblSubMenu table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblSubMenu_Update
(

	@Id int   ,

	@Code varchar (50)  ,

	@Name nvarchar (128)  ,

	@Link nvarchar (512)  ,

	@MainMenuId int   ,

	@ParentId int   ,

	@FunctionId bigint   ,

	@Order int   ,

	@LayoutPosition int   
)
AS


				
				
				-- Modify the updatable columns
				UPDATE
					[dbo].[tblSubMenu]
				SET
					[Code] = @Code
					,[Name] = @Name
					,[Link] = @Link
					,[MainMenuId] = @MainMenuId
					,[ParentId] = @ParentId
					,[FunctionId] = @FunctionId
					,[Order] = @Order
					,[LayoutPosition] = @LayoutPosition
				WHERE
[Id] = @Id 
				
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblSubMenu_Delete procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblSubMenu_Delete') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblSubMenu_Delete
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Deletes a record in the tblSubMenu table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblSubMenu_Delete
(

	@Id int   
)
AS


				DELETE FROM [dbo].[tblSubMenu] WITH (ROWLOCK) 
				WHERE
					[Id] = @Id
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblSubMenu_GetByParentId procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblSubMenu_GetByParentId') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblSubMenu_GetByParentId
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Select records from the tblSubMenu table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblSubMenu_GetByParentId
(

	@ParentId int   
)
AS


				SET ANSI_NULLS OFF
				
				SELECT
					[Id],
					[Code],
					[Name],
					[Link],
					[MainMenuId],
					[ParentId],
					[FunctionId],
					[Order],
					[LayoutPosition]
				FROM
					[dbo].[tblSubMenu]
				WHERE
					[ParentId] = @ParentId
				
				SELECT @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblSubMenu_GetByMainMenuId procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblSubMenu_GetByMainMenuId') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblSubMenu_GetByMainMenuId
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Select records from the tblSubMenu table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblSubMenu_GetByMainMenuId
(

	@MainMenuId int   
)
AS


				SET ANSI_NULLS OFF
				
				SELECT
					[Id],
					[Code],
					[Name],
					[Link],
					[MainMenuId],
					[ParentId],
					[FunctionId],
					[Order],
					[LayoutPosition]
				FROM
					[dbo].[tblSubMenu]
				WHERE
					[MainMenuId] = @MainMenuId
				
				SELECT @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblSubMenu_GetById procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblSubMenu_GetById') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblSubMenu_GetById
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Select records from the tblSubMenu table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblSubMenu_GetById
(

	@Id int   
)
AS


				SELECT
					[Id],
					[Code],
					[Name],
					[Link],
					[MainMenuId],
					[ParentId],
					[FunctionId],
					[Order],
					[LayoutPosition]
				FROM
					[dbo].[tblSubMenu]
				WHERE
					[Id] = @Id
				SELECT @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblSubMenu_GetByCode procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblSubMenu_GetByCode') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblSubMenu_GetByCode
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Select records from the tblSubMenu table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblSubMenu_GetByCode
(

	@Code varchar (50)  
)
AS


				SELECT
					[Id],
					[Code],
					[Name],
					[Link],
					[MainMenuId],
					[ParentId],
					[FunctionId],
					[Order],
					[LayoutPosition]
				FROM
					[dbo].[tblSubMenu]
				WHERE
					[Code] = @Code
				SELECT @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblSubMenu_Find procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblSubMenu_Find') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblSubMenu_Find
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Finds records in the tblSubMenu table passing nullable parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblSubMenu_Find
(

	@SearchUsingOR bit   = null ,

	@Id int   = null ,

	@Code varchar (50)  = null ,

	@Name nvarchar (128)  = null ,

	@Link nvarchar (512)  = null ,

	@MainMenuId int   = null ,

	@ParentId int   = null ,

	@FunctionId bigint   = null ,

	@Order int   = null ,

	@LayoutPosition int   = null 
)
AS


				
  IF ISNULL(@SearchUsingOR, 0) <> 1
  BEGIN
    SELECT
	  [Id]
	, [Code]
	, [Name]
	, [Link]
	, [MainMenuId]
	, [ParentId]
	, [FunctionId]
	, [Order]
	, [LayoutPosition]
    FROM
	[dbo].[tblSubMenu]
    WHERE 
	 ([Id] = @Id OR @Id IS NULL)
	AND ([Code] = @Code OR @Code IS NULL)
	AND ([Name] = @Name OR @Name IS NULL)
	AND ([Link] = @Link OR @Link IS NULL)
	AND ([MainMenuId] = @MainMenuId OR @MainMenuId IS NULL)
	AND ([ParentId] = @ParentId OR @ParentId IS NULL)
	AND ([FunctionId] = @FunctionId OR @FunctionId IS NULL)
	AND ([Order] = @Order OR @Order IS NULL)
	AND ([LayoutPosition] = @LayoutPosition OR @LayoutPosition IS NULL)
						
  END
  ELSE
  BEGIN
    SELECT
	  [Id]
	, [Code]
	, [Name]
	, [Link]
	, [MainMenuId]
	, [ParentId]
	, [FunctionId]
	, [Order]
	, [LayoutPosition]
    FROM
	[dbo].[tblSubMenu]
    WHERE 
	 ([Id] = @Id AND @Id is not null)
	OR ([Code] = @Code AND @Code is not null)
	OR ([Name] = @Name AND @Name is not null)
	OR ([Link] = @Link AND @Link is not null)
	OR ([MainMenuId] = @MainMenuId AND @MainMenuId is not null)
	OR ([ParentId] = @ParentId AND @ParentId is not null)
	OR ([FunctionId] = @FunctionId AND @FunctionId is not null)
	OR ([Order] = @Order AND @Order is not null)
	OR ([LayoutPosition] = @LayoutPosition AND @LayoutPosition is not null)
	SELECT @@ROWCOUNT			
  END
				

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblProductFeature_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblProductFeature_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblProductFeature_Get_List
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Gets all records from the tblProductFeature table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblProductFeature_Get_List

AS


				
				SELECT
					[Id],
					[FeatureId],
					[ProductId],
					[Content]
				FROM
					[dbo].[tblProductFeature]
					
				SELECT @@ROWCOUNT
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblProductFeature_GetPaged procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblProductFeature_GetPaged') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblProductFeature_GetPaged
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Gets records from the tblProductFeature table passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblProductFeature_GetPaged
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				
				BEGIN
				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				-- Create a temp table to store the select results
				CREATE TABLE #PageIndex
				(
				    [IndexId] int IDENTITY (1, 1) NOT NULL,
				    [Id] int 
				)
				
				-- Insert into the temp table
				DECLARE @SQL AS nvarchar(4000)
				SET @SQL = 'INSERT INTO #PageIndex ([Id])'
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + CONVERT(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' [Id]'
				SET @SQL = @SQL + ' FROM [dbo].[tblProductFeature]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				IF LEN(@OrderBy) > 0
				BEGIN
					SET @SQL = @SQL + ' ORDER BY ' + @OrderBy
				END
				
				-- Populate the temp table
				EXEC sp_executesql @SQL

				-- Return paged results
				SELECT O.[Id], O.[FeatureId], O.[ProductId], O.[Content]
				FROM
				    [dbo].[tblProductFeature] O,
				    #PageIndex PageIndex
				WHERE
				    PageIndex.IndexId > @PageLowerBound
					AND O.[Id] = PageIndex.[Id]
				ORDER BY
				    PageIndex.IndexId
				
				-- get row count
				SET @SQL = 'SELECT COUNT(*) AS TotalRowCount'
				SET @SQL = @SQL + ' FROM [dbo].[tblProductFeature]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				EXEC sp_executesql @SQL
			
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblProductFeature_Insert procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblProductFeature_Insert') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblProductFeature_Insert
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Inserts a record into the tblProductFeature table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblProductFeature_Insert
(

	@Id int    OUTPUT,

	@FeatureId int   ,

	@ProductId int   ,

	@Content ntext   
)
AS


				
				INSERT INTO [dbo].[tblProductFeature]
					(
					[FeatureId]
					,[ProductId]
					,[Content]
					)
				VALUES
					(
					@FeatureId
					,@ProductId
					,@Content
					)
				
				-- Get the identity value
				SET @Id = SCOPE_IDENTITY()
									
							
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblProductFeature_Update procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblProductFeature_Update') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblProductFeature_Update
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Updates a record in the tblProductFeature table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblProductFeature_Update
(

	@Id int   ,

	@FeatureId int   ,

	@ProductId int   ,

	@Content ntext   
)
AS


				
				
				-- Modify the updatable columns
				UPDATE
					[dbo].[tblProductFeature]
				SET
					[FeatureId] = @FeatureId
					,[ProductId] = @ProductId
					,[Content] = @Content
				WHERE
[Id] = @Id 
				
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblProductFeature_Delete procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblProductFeature_Delete') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblProductFeature_Delete
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Deletes a record in the tblProductFeature table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblProductFeature_Delete
(

	@Id int   
)
AS


				DELETE FROM [dbo].[tblProductFeature] WITH (ROWLOCK) 
				WHERE
					[Id] = @Id
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblProductFeature_GetByFeatureId procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblProductFeature_GetByFeatureId') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblProductFeature_GetByFeatureId
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Select records from the tblProductFeature table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblProductFeature_GetByFeatureId
(

	@FeatureId int   
)
AS


				SET ANSI_NULLS OFF
				
				SELECT
					[Id],
					[FeatureId],
					[ProductId],
					[Content]
				FROM
					[dbo].[tblProductFeature]
				WHERE
					[FeatureId] = @FeatureId
				
				SELECT @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblProductFeature_GetByProductId procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblProductFeature_GetByProductId') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblProductFeature_GetByProductId
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Select records from the tblProductFeature table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblProductFeature_GetByProductId
(

	@ProductId int   
)
AS


				SET ANSI_NULLS OFF
				
				SELECT
					[Id],
					[FeatureId],
					[ProductId],
					[Content]
				FROM
					[dbo].[tblProductFeature]
				WHERE
					[ProductId] = @ProductId
				
				SELECT @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblProductFeature_GetById procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblProductFeature_GetById') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblProductFeature_GetById
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Select records from the tblProductFeature table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblProductFeature_GetById
(

	@Id int   
)
AS


				SELECT
					[Id],
					[FeatureId],
					[ProductId],
					[Content]
				FROM
					[dbo].[tblProductFeature]
				WHERE
					[Id] = @Id
				SELECT @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblProductFeature_Find procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblProductFeature_Find') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblProductFeature_Find
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Finds records in the tblProductFeature table passing nullable parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblProductFeature_Find
(

	@SearchUsingOR bit   = null ,

	@Id int   = null ,

	@FeatureId int   = null ,

	@ProductId int   = null ,

	@Content ntext   = null 
)
AS


				
  IF ISNULL(@SearchUsingOR, 0) <> 1
  BEGIN
    SELECT
	  [Id]
	, [FeatureId]
	, [ProductId]
	, [Content]
    FROM
	[dbo].[tblProductFeature]
    WHERE 
	 ([Id] = @Id OR @Id IS NULL)
	AND ([FeatureId] = @FeatureId OR @FeatureId IS NULL)
	AND ([ProductId] = @ProductId OR @ProductId IS NULL)
						
  END
  ELSE
  BEGIN
    SELECT
	  [Id]
	, [FeatureId]
	, [ProductId]
	, [Content]
    FROM
	[dbo].[tblProductFeature]
    WHERE 
	 ([Id] = @Id AND @Id is not null)
	OR ([FeatureId] = @FeatureId AND @FeatureId is not null)
	OR ([ProductId] = @ProductId AND @ProductId is not null)
	SELECT @@ROWCOUNT			
  END
				

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblSurveyDetail_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblSurveyDetail_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblSurveyDetail_Get_List
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Gets all records from the tblSurveyDetail table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblSurveyDetail_Get_List

AS


				
				SELECT
					[Id],
					[SurveyId],
					[Type],
					[Value],
					[LastModified],
					[Name]
				FROM
					[dbo].[tblSurveyDetail]
					
				SELECT @@ROWCOUNT
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblSurveyDetail_GetPaged procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblSurveyDetail_GetPaged') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblSurveyDetail_GetPaged
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Gets records from the tblSurveyDetail table passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblSurveyDetail_GetPaged
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				
				BEGIN
				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				-- Create a temp table to store the select results
				CREATE TABLE #PageIndex
				(
				    [IndexId] int IDENTITY (1, 1) NOT NULL,
				    [Id] int 
				)
				
				-- Insert into the temp table
				DECLARE @SQL AS nvarchar(4000)
				SET @SQL = 'INSERT INTO #PageIndex ([Id])'
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + CONVERT(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' [Id]'
				SET @SQL = @SQL + ' FROM [dbo].[tblSurveyDetail]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				IF LEN(@OrderBy) > 0
				BEGIN
					SET @SQL = @SQL + ' ORDER BY ' + @OrderBy
				END
				
				-- Populate the temp table
				EXEC sp_executesql @SQL

				-- Return paged results
				SELECT O.[Id], O.[SurveyId], O.[Type], O.[Value], O.[LastModified], O.[Name]
				FROM
				    [dbo].[tblSurveyDetail] O,
				    #PageIndex PageIndex
				WHERE
				    PageIndex.IndexId > @PageLowerBound
					AND O.[Id] = PageIndex.[Id]
				ORDER BY
				    PageIndex.IndexId
				
				-- get row count
				SET @SQL = 'SELECT COUNT(*) AS TotalRowCount'
				SET @SQL = @SQL + ' FROM [dbo].[tblSurveyDetail]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				EXEC sp_executesql @SQL
			
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblSurveyDetail_Insert procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblSurveyDetail_Insert') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblSurveyDetail_Insert
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Inserts a record into the tblSurveyDetail table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblSurveyDetail_Insert
(

	@Id int    OUTPUT,

	@SurveyId int   ,

	@Type char (1)  ,

	@Value nvarchar (256)  ,

	@LastModified datetime   ,

	@Name nvarchar (256)  
)
AS


				
				INSERT INTO [dbo].[tblSurveyDetail]
					(
					[SurveyId]
					,[Type]
					,[Value]
					,[LastModified]
					,[Name]
					)
				VALUES
					(
					@SurveyId
					,@Type
					,@Value
					,@LastModified
					,@Name
					)
				
				-- Get the identity value
				SET @Id = SCOPE_IDENTITY()
									
							
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblSurveyDetail_Update procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblSurveyDetail_Update') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblSurveyDetail_Update
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Updates a record in the tblSurveyDetail table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblSurveyDetail_Update
(

	@Id int   ,

	@SurveyId int   ,

	@Type char (1)  ,

	@Value nvarchar (256)  ,

	@LastModified datetime   ,

	@Name nvarchar (256)  
)
AS


				
				
				-- Modify the updatable columns
				UPDATE
					[dbo].[tblSurveyDetail]
				SET
					[SurveyId] = @SurveyId
					,[Type] = @Type
					,[Value] = @Value
					,[LastModified] = @LastModified
					,[Name] = @Name
				WHERE
[Id] = @Id 
				
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblSurveyDetail_Delete procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblSurveyDetail_Delete') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblSurveyDetail_Delete
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Deletes a record in the tblSurveyDetail table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblSurveyDetail_Delete
(

	@Id int   
)
AS


				DELETE FROM [dbo].[tblSurveyDetail] WITH (ROWLOCK) 
				WHERE
					[Id] = @Id
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblSurveyDetail_GetBySurveyId procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblSurveyDetail_GetBySurveyId') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblSurveyDetail_GetBySurveyId
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Select records from the tblSurveyDetail table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblSurveyDetail_GetBySurveyId
(

	@SurveyId int   
)
AS


				SET ANSI_NULLS OFF
				
				SELECT
					[Id],
					[SurveyId],
					[Type],
					[Value],
					[LastModified],
					[Name]
				FROM
					[dbo].[tblSurveyDetail]
				WHERE
					[SurveyId] = @SurveyId
				
				SELECT @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblSurveyDetail_GetById procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblSurveyDetail_GetById') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblSurveyDetail_GetById
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Select records from the tblSurveyDetail table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblSurveyDetail_GetById
(

	@Id int   
)
AS


				SELECT
					[Id],
					[SurveyId],
					[Type],
					[Value],
					[LastModified],
					[Name]
				FROM
					[dbo].[tblSurveyDetail]
				WHERE
					[Id] = @Id
				SELECT @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblSurveyDetail_Find procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblSurveyDetail_Find') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblSurveyDetail_Find
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Finds records in the tblSurveyDetail table passing nullable parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblSurveyDetail_Find
(

	@SearchUsingOR bit   = null ,

	@Id int   = null ,

	@SurveyId int   = null ,

	@Type char (1)  = null ,

	@Value nvarchar (256)  = null ,

	@LastModified datetime   = null ,

	@Name nvarchar (256)  = null 
)
AS


				
  IF ISNULL(@SearchUsingOR, 0) <> 1
  BEGIN
    SELECT
	  [Id]
	, [SurveyId]
	, [Type]
	, [Value]
	, [LastModified]
	, [Name]
    FROM
	[dbo].[tblSurveyDetail]
    WHERE 
	 ([Id] = @Id OR @Id IS NULL)
	AND ([SurveyId] = @SurveyId OR @SurveyId IS NULL)
	AND ([Type] = @Type OR @Type IS NULL)
	AND ([Value] = @Value OR @Value IS NULL)
	AND ([LastModified] = @LastModified OR @LastModified IS NULL)
	AND ([Name] = @Name OR @Name IS NULL)
						
  END
  ELSE
  BEGIN
    SELECT
	  [Id]
	, [SurveyId]
	, [Type]
	, [Value]
	, [LastModified]
	, [Name]
    FROM
	[dbo].[tblSurveyDetail]
    WHERE 
	 ([Id] = @Id AND @Id is not null)
	OR ([SurveyId] = @SurveyId AND @SurveyId is not null)
	OR ([Type] = @Type AND @Type is not null)
	OR ([Value] = @Value AND @Value is not null)
	OR ([LastModified] = @LastModified AND @LastModified is not null)
	OR ([Name] = @Name AND @Name is not null)
	SELECT @@ROWCOUNT			
  END
				

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblNews_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblNews_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblNews_Get_List
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Gets all records from the tblNews table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblNews_Get_List

AS


				
				SELECT
					[Id],
					[CategoryId],
					[Code],
					[Title],
					[ImagePath],
					[Summary],
					[Content],
					[PostDate],
					[Source],
					[CreatedDate],
					[CreatedBy],
					[ModifiedDate],
					[ModifiedBy],
					[ApprovedDate],
					[ApprovedBy],
					[IsHotNews],
					[IsActive],
					[Status],
					[ViewCount],
					[Tags],
					[Type]
				FROM
					[dbo].[tblNews]
					
				SELECT @@ROWCOUNT
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblNews_GetPaged procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblNews_GetPaged') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblNews_GetPaged
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Gets records from the tblNews table passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblNews_GetPaged
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				
				BEGIN
				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				-- Create a temp table to store the select results
				CREATE TABLE #PageIndex
				(
				    [IndexId] int IDENTITY (1, 1) NOT NULL,
				    [Id] int 
				)
				
				-- Insert into the temp table
				DECLARE @SQL AS nvarchar(4000)
				SET @SQL = 'INSERT INTO #PageIndex ([Id])'
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + CONVERT(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' [Id]'
				SET @SQL = @SQL + ' FROM [dbo].[tblNews]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				IF LEN(@OrderBy) > 0
				BEGIN
					SET @SQL = @SQL + ' ORDER BY ' + @OrderBy
				END
				
				-- Populate the temp table
				EXEC sp_executesql @SQL

				-- Return paged results
				SELECT O.[Id], O.[CategoryId], O.[Code], O.[Title], O.[ImagePath], O.[Summary], O.[Content], O.[PostDate], O.[Source], O.[CreatedDate], O.[CreatedBy], O.[ModifiedDate], O.[ModifiedBy], O.[ApprovedDate], O.[ApprovedBy], O.[IsHotNews], O.[IsActive], O.[Status], O.[ViewCount], O.[Tags], O.[Type]
				FROM
				    [dbo].[tblNews] O,
				    #PageIndex PageIndex
				WHERE
				    PageIndex.IndexId > @PageLowerBound
					AND O.[Id] = PageIndex.[Id]
				ORDER BY
				    PageIndex.IndexId
				
				-- get row count
				SET @SQL = 'SELECT COUNT(*) AS TotalRowCount'
				SET @SQL = @SQL + ' FROM [dbo].[tblNews]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				EXEC sp_executesql @SQL
			
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblNews_Insert procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblNews_Insert') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblNews_Insert
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Inserts a record into the tblNews table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblNews_Insert
(

	@Id int    OUTPUT,

	@CategoryId int   ,

	@Code varchar (900)  ,

	@Title nvarchar (900)  ,

	@ImagePath nvarchar (512)  ,

	@Summary nvarchar (1024)  ,

	@Content ntext   ,

	@PostDate datetime   ,

	@Source nvarchar (1024)  ,

	@CreatedDate datetime   ,

	@CreatedBy varchar (50)  ,

	@ModifiedDate datetime   ,

	@ModifiedBy varchar (50)  ,

	@ApprovedDate datetime   ,

	@ApprovedBy varchar (50)  ,

	@IsHotNews bit   ,

	@IsActive bit   ,

	@Status char (1)  ,

	@ViewCount int   ,

	@Tags nvarchar (1024)  ,

	@Type char (1)  
)
AS


				
				INSERT INTO [dbo].[tblNews]
					(
					[CategoryId]
					,[Code]
					,[Title]
					,[ImagePath]
					,[Summary]
					,[Content]
					,[PostDate]
					,[Source]
					,[CreatedDate]
					,[CreatedBy]
					,[ModifiedDate]
					,[ModifiedBy]
					,[ApprovedDate]
					,[ApprovedBy]
					,[IsHotNews]
					,[IsActive]
					,[Status]
					,[ViewCount]
					,[Tags]
					,[Type]
					)
				VALUES
					(
					@CategoryId
					,@Code
					,@Title
					,@ImagePath
					,@Summary
					,@Content
					,@PostDate
					,@Source
					,@CreatedDate
					,@CreatedBy
					,@ModifiedDate
					,@ModifiedBy
					,@ApprovedDate
					,@ApprovedBy
					,@IsHotNews
					,@IsActive
					,@Status
					,@ViewCount
					,@Tags
					,@Type
					)
				
				-- Get the identity value
				SET @Id = SCOPE_IDENTITY()
									
							
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblNews_Update procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblNews_Update') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblNews_Update
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Updates a record in the tblNews table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblNews_Update
(

	@Id int   ,

	@CategoryId int   ,

	@Code varchar (900)  ,

	@Title nvarchar (900)  ,

	@ImagePath nvarchar (512)  ,

	@Summary nvarchar (1024)  ,

	@Content ntext   ,

	@PostDate datetime   ,

	@Source nvarchar (1024)  ,

	@CreatedDate datetime   ,

	@CreatedBy varchar (50)  ,

	@ModifiedDate datetime   ,

	@ModifiedBy varchar (50)  ,

	@ApprovedDate datetime   ,

	@ApprovedBy varchar (50)  ,

	@IsHotNews bit   ,

	@IsActive bit   ,

	@Status char (1)  ,

	@ViewCount int   ,

	@Tags nvarchar (1024)  ,

	@Type char (1)  
)
AS


				
				
				-- Modify the updatable columns
				UPDATE
					[dbo].[tblNews]
				SET
					[CategoryId] = @CategoryId
					,[Code] = @Code
					,[Title] = @Title
					,[ImagePath] = @ImagePath
					,[Summary] = @Summary
					,[Content] = @Content
					,[PostDate] = @PostDate
					,[Source] = @Source
					,[CreatedDate] = @CreatedDate
					,[CreatedBy] = @CreatedBy
					,[ModifiedDate] = @ModifiedDate
					,[ModifiedBy] = @ModifiedBy
					,[ApprovedDate] = @ApprovedDate
					,[ApprovedBy] = @ApprovedBy
					,[IsHotNews] = @IsHotNews
					,[IsActive] = @IsActive
					,[Status] = @Status
					,[ViewCount] = @ViewCount
					,[Tags] = @Tags
					,[Type] = @Type
				WHERE
[Id] = @Id 
				
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblNews_Delete procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblNews_Delete') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblNews_Delete
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Deletes a record in the tblNews table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblNews_Delete
(

	@Id int   
)
AS


				DELETE FROM [dbo].[tblNews] WITH (ROWLOCK) 
				WHERE
					[Id] = @Id
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblNews_GetByCategoryId procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblNews_GetByCategoryId') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblNews_GetByCategoryId
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Select records from the tblNews table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblNews_GetByCategoryId
(

	@CategoryId int   
)
AS


				SET ANSI_NULLS OFF
				
				SELECT
					[Id],
					[CategoryId],
					[Code],
					[Title],
					[ImagePath],
					[Summary],
					[Content],
					[PostDate],
					[Source],
					[CreatedDate],
					[CreatedBy],
					[ModifiedDate],
					[ModifiedBy],
					[ApprovedDate],
					[ApprovedBy],
					[IsHotNews],
					[IsActive],
					[Status],
					[ViewCount],
					[Tags],
					[Type]
				FROM
					[dbo].[tblNews]
				WHERE
					[CategoryId] = @CategoryId
				
				SELECT @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblNews_GetById procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblNews_GetById') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblNews_GetById
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Select records from the tblNews table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblNews_GetById
(

	@Id int   
)
AS


				SELECT
					[Id],
					[CategoryId],
					[Code],
					[Title],
					[ImagePath],
					[Summary],
					[Content],
					[PostDate],
					[Source],
					[CreatedDate],
					[CreatedBy],
					[ModifiedDate],
					[ModifiedBy],
					[ApprovedDate],
					[ApprovedBy],
					[IsHotNews],
					[IsActive],
					[Status],
					[ViewCount],
					[Tags],
					[Type]
				FROM
					[dbo].[tblNews]
				WHERE
					[Id] = @Id
				SELECT @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblNews_GetByCode procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblNews_GetByCode') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblNews_GetByCode
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Select records from the tblNews table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblNews_GetByCode
(

	@Code varchar (900)  
)
AS


				SELECT
					[Id],
					[CategoryId],
					[Code],
					[Title],
					[ImagePath],
					[Summary],
					[Content],
					[PostDate],
					[Source],
					[CreatedDate],
					[CreatedBy],
					[ModifiedDate],
					[ModifiedBy],
					[ApprovedDate],
					[ApprovedBy],
					[IsHotNews],
					[IsActive],
					[Status],
					[ViewCount],
					[Tags],
					[Type]
				FROM
					[dbo].[tblNews]
				WHERE
					[Code] = @Code
				SELECT @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblNews_Find procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblNews_Find') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblNews_Find
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Finds records in the tblNews table passing nullable parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblNews_Find
(

	@SearchUsingOR bit   = null ,

	@Id int   = null ,

	@CategoryId int   = null ,

	@Code varchar (900)  = null ,

	@Title nvarchar (900)  = null ,

	@ImagePath nvarchar (512)  = null ,

	@Summary nvarchar (1024)  = null ,

	@Content ntext   = null ,

	@PostDate datetime   = null ,

	@Source nvarchar (1024)  = null ,

	@CreatedDate datetime   = null ,

	@CreatedBy varchar (50)  = null ,

	@ModifiedDate datetime   = null ,

	@ModifiedBy varchar (50)  = null ,

	@ApprovedDate datetime   = null ,

	@ApprovedBy varchar (50)  = null ,

	@IsHotNews bit   = null ,

	@IsActive bit   = null ,

	@Status char (1)  = null ,

	@ViewCount int   = null ,

	@Tags nvarchar (1024)  = null ,

	@Type char (1)  = null 
)
AS


				
  IF ISNULL(@SearchUsingOR, 0) <> 1
  BEGIN
    SELECT
	  [Id]
	, [CategoryId]
	, [Code]
	, [Title]
	, [ImagePath]
	, [Summary]
	, [Content]
	, [PostDate]
	, [Source]
	, [CreatedDate]
	, [CreatedBy]
	, [ModifiedDate]
	, [ModifiedBy]
	, [ApprovedDate]
	, [ApprovedBy]
	, [IsHotNews]
	, [IsActive]
	, [Status]
	, [ViewCount]
	, [Tags]
	, [Type]
    FROM
	[dbo].[tblNews]
    WHERE 
	 ([Id] = @Id OR @Id IS NULL)
	AND ([CategoryId] = @CategoryId OR @CategoryId IS NULL)
	AND ([Code] = @Code OR @Code IS NULL)
	AND ([Title] = @Title OR @Title IS NULL)
	AND ([ImagePath] = @ImagePath OR @ImagePath IS NULL)
	AND ([Summary] = @Summary OR @Summary IS NULL)
	AND ([PostDate] = @PostDate OR @PostDate IS NULL)
	AND ([Source] = @Source OR @Source IS NULL)
	AND ([CreatedDate] = @CreatedDate OR @CreatedDate IS NULL)
	AND ([CreatedBy] = @CreatedBy OR @CreatedBy IS NULL)
	AND ([ModifiedDate] = @ModifiedDate OR @ModifiedDate IS NULL)
	AND ([ModifiedBy] = @ModifiedBy OR @ModifiedBy IS NULL)
	AND ([ApprovedDate] = @ApprovedDate OR @ApprovedDate IS NULL)
	AND ([ApprovedBy] = @ApprovedBy OR @ApprovedBy IS NULL)
	AND ([IsHotNews] = @IsHotNews OR @IsHotNews IS NULL)
	AND ([IsActive] = @IsActive OR @IsActive IS NULL)
	AND ([Status] = @Status OR @Status IS NULL)
	AND ([ViewCount] = @ViewCount OR @ViewCount IS NULL)
	AND ([Tags] = @Tags OR @Tags IS NULL)
	AND ([Type] = @Type OR @Type IS NULL)
						
  END
  ELSE
  BEGIN
    SELECT
	  [Id]
	, [CategoryId]
	, [Code]
	, [Title]
	, [ImagePath]
	, [Summary]
	, [Content]
	, [PostDate]
	, [Source]
	, [CreatedDate]
	, [CreatedBy]
	, [ModifiedDate]
	, [ModifiedBy]
	, [ApprovedDate]
	, [ApprovedBy]
	, [IsHotNews]
	, [IsActive]
	, [Status]
	, [ViewCount]
	, [Tags]
	, [Type]
    FROM
	[dbo].[tblNews]
    WHERE 
	 ([Id] = @Id AND @Id is not null)
	OR ([CategoryId] = @CategoryId AND @CategoryId is not null)
	OR ([Code] = @Code AND @Code is not null)
	OR ([Title] = @Title AND @Title is not null)
	OR ([ImagePath] = @ImagePath AND @ImagePath is not null)
	OR ([Summary] = @Summary AND @Summary is not null)
	OR ([PostDate] = @PostDate AND @PostDate is not null)
	OR ([Source] = @Source AND @Source is not null)
	OR ([CreatedDate] = @CreatedDate AND @CreatedDate is not null)
	OR ([CreatedBy] = @CreatedBy AND @CreatedBy is not null)
	OR ([ModifiedDate] = @ModifiedDate AND @ModifiedDate is not null)
	OR ([ModifiedBy] = @ModifiedBy AND @ModifiedBy is not null)
	OR ([ApprovedDate] = @ApprovedDate AND @ApprovedDate is not null)
	OR ([ApprovedBy] = @ApprovedBy AND @ApprovedBy is not null)
	OR ([IsHotNews] = @IsHotNews AND @IsHotNews is not null)
	OR ([IsActive] = @IsActive AND @IsActive is not null)
	OR ([Status] = @Status AND @Status is not null)
	OR ([ViewCount] = @ViewCount AND @ViewCount is not null)
	OR ([Tags] = @Tags AND @Tags is not null)
	OR ([Type] = @Type AND @Type is not null)
	SELECT @@ROWCOUNT			
  END
				

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblSubMenuLocale_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblSubMenuLocale_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblSubMenuLocale_Get_List
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Gets all records from the tblSubMenuLocale table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblSubMenuLocale_Get_List

AS


				
				SELECT
					[Id],
					[SubMenuId],
					[LanguageId],
					[Name]
				FROM
					[dbo].[tblSubMenuLocale]
					
				SELECT @@ROWCOUNT
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblSubMenuLocale_GetPaged procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblSubMenuLocale_GetPaged') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblSubMenuLocale_GetPaged
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Gets records from the tblSubMenuLocale table passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblSubMenuLocale_GetPaged
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				
				BEGIN
				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				-- Create a temp table to store the select results
				CREATE TABLE #PageIndex
				(
				    [IndexId] int IDENTITY (1, 1) NOT NULL,
				    [Id] int 
				)
				
				-- Insert into the temp table
				DECLARE @SQL AS nvarchar(4000)
				SET @SQL = 'INSERT INTO #PageIndex ([Id])'
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + CONVERT(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' [Id]'
				SET @SQL = @SQL + ' FROM [dbo].[tblSubMenuLocale]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				IF LEN(@OrderBy) > 0
				BEGIN
					SET @SQL = @SQL + ' ORDER BY ' + @OrderBy
				END
				
				-- Populate the temp table
				EXEC sp_executesql @SQL

				-- Return paged results
				SELECT O.[Id], O.[SubMenuId], O.[LanguageId], O.[Name]
				FROM
				    [dbo].[tblSubMenuLocale] O,
				    #PageIndex PageIndex
				WHERE
				    PageIndex.IndexId > @PageLowerBound
					AND O.[Id] = PageIndex.[Id]
				ORDER BY
				    PageIndex.IndexId
				
				-- get row count
				SET @SQL = 'SELECT COUNT(*) AS TotalRowCount'
				SET @SQL = @SQL + ' FROM [dbo].[tblSubMenuLocale]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				EXEC sp_executesql @SQL
			
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblSubMenuLocale_Insert procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblSubMenuLocale_Insert') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblSubMenuLocale_Insert
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Inserts a record into the tblSubMenuLocale table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblSubMenuLocale_Insert
(

	@Id int    OUTPUT,

	@SubMenuId int   ,

	@LanguageId int   ,

	@Name nvarchar (128)  
)
AS


				
				INSERT INTO [dbo].[tblSubMenuLocale]
					(
					[SubMenuId]
					,[LanguageId]
					,[Name]
					)
				VALUES
					(
					@SubMenuId
					,@LanguageId
					,@Name
					)
				
				-- Get the identity value
				SET @Id = SCOPE_IDENTITY()
									
							
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblSubMenuLocale_Update procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblSubMenuLocale_Update') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblSubMenuLocale_Update
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Updates a record in the tblSubMenuLocale table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblSubMenuLocale_Update
(

	@Id int   ,

	@SubMenuId int   ,

	@LanguageId int   ,

	@Name nvarchar (128)  
)
AS


				
				
				-- Modify the updatable columns
				UPDATE
					[dbo].[tblSubMenuLocale]
				SET
					[SubMenuId] = @SubMenuId
					,[LanguageId] = @LanguageId
					,[Name] = @Name
				WHERE
[Id] = @Id 
				
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblSubMenuLocale_Delete procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblSubMenuLocale_Delete') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblSubMenuLocale_Delete
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Deletes a record in the tblSubMenuLocale table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblSubMenuLocale_Delete
(

	@Id int   
)
AS


				DELETE FROM [dbo].[tblSubMenuLocale] WITH (ROWLOCK) 
				WHERE
					[Id] = @Id
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblSubMenuLocale_GetBySubMenuId procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblSubMenuLocale_GetBySubMenuId') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblSubMenuLocale_GetBySubMenuId
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Select records from the tblSubMenuLocale table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblSubMenuLocale_GetBySubMenuId
(

	@SubMenuId int   
)
AS


				SET ANSI_NULLS OFF
				
				SELECT
					[Id],
					[SubMenuId],
					[LanguageId],
					[Name]
				FROM
					[dbo].[tblSubMenuLocale]
				WHERE
					[SubMenuId] = @SubMenuId
				
				SELECT @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblSubMenuLocale_GetByLanguageId procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblSubMenuLocale_GetByLanguageId') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblSubMenuLocale_GetByLanguageId
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Select records from the tblSubMenuLocale table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblSubMenuLocale_GetByLanguageId
(

	@LanguageId int   
)
AS


				SET ANSI_NULLS OFF
				
				SELECT
					[Id],
					[SubMenuId],
					[LanguageId],
					[Name]
				FROM
					[dbo].[tblSubMenuLocale]
				WHERE
					[LanguageId] = @LanguageId
				
				SELECT @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblSubMenuLocale_GetById procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblSubMenuLocale_GetById') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblSubMenuLocale_GetById
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Select records from the tblSubMenuLocale table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblSubMenuLocale_GetById
(

	@Id int   
)
AS


				SELECT
					[Id],
					[SubMenuId],
					[LanguageId],
					[Name]
				FROM
					[dbo].[tblSubMenuLocale]
				WHERE
					[Id] = @Id
				SELECT @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblSubMenuLocale_Find procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblSubMenuLocale_Find') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblSubMenuLocale_Find
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Finds records in the tblSubMenuLocale table passing nullable parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblSubMenuLocale_Find
(

	@SearchUsingOR bit   = null ,

	@Id int   = null ,

	@SubMenuId int   = null ,

	@LanguageId int   = null ,

	@Name nvarchar (128)  = null 
)
AS


				
  IF ISNULL(@SearchUsingOR, 0) <> 1
  BEGIN
    SELECT
	  [Id]
	, [SubMenuId]
	, [LanguageId]
	, [Name]
    FROM
	[dbo].[tblSubMenuLocale]
    WHERE 
	 ([Id] = @Id OR @Id IS NULL)
	AND ([SubMenuId] = @SubMenuId OR @SubMenuId IS NULL)
	AND ([LanguageId] = @LanguageId OR @LanguageId IS NULL)
	AND ([Name] = @Name OR @Name IS NULL)
						
  END
  ELSE
  BEGIN
    SELECT
	  [Id]
	, [SubMenuId]
	, [LanguageId]
	, [Name]
    FROM
	[dbo].[tblSubMenuLocale]
    WHERE 
	 ([Id] = @Id AND @Id is not null)
	OR ([SubMenuId] = @SubMenuId AND @SubMenuId is not null)
	OR ([LanguageId] = @LanguageId AND @LanguageId is not null)
	OR ([Name] = @Name AND @Name is not null)
	SELECT @@ROWCOUNT			
  END
				

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblCustomerOpinion_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblCustomerOpinion_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblCustomerOpinion_Get_List
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Gets all records from the tblCustomerOpinion table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblCustomerOpinion_Get_List

AS


				
				SELECT
					[Id],
					[Date],
					[Fullname],
					[Email],
					[Phone],
					[Address],
					[Answer],
					[Opinion],
					[Title],
					[Code],
					[LanguageId],
					[IsActive],
					[Type],
					[Tags]
				FROM
					[dbo].[tblCustomerOpinion]
					
				SELECT @@ROWCOUNT
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblCustomerOpinion_GetPaged procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblCustomerOpinion_GetPaged') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblCustomerOpinion_GetPaged
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Gets records from the tblCustomerOpinion table passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblCustomerOpinion_GetPaged
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				
				BEGIN
				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				-- Create a temp table to store the select results
				CREATE TABLE #PageIndex
				(
				    [IndexId] int IDENTITY (1, 1) NOT NULL,
				    [Id] int 
				)
				
				-- Insert into the temp table
				DECLARE @SQL AS nvarchar(4000)
				SET @SQL = 'INSERT INTO #PageIndex ([Id])'
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + CONVERT(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' [Id]'
				SET @SQL = @SQL + ' FROM [dbo].[tblCustomerOpinion]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				IF LEN(@OrderBy) > 0
				BEGIN
					SET @SQL = @SQL + ' ORDER BY ' + @OrderBy
				END
				
				-- Populate the temp table
				EXEC sp_executesql @SQL

				-- Return paged results
				SELECT O.[Id], O.[Date], O.[Fullname], O.[Email], O.[Phone], O.[Address], O.[Answer], O.[Opinion], O.[Title], O.[Code], O.[LanguageId], O.[IsActive], O.[Type], O.[Tags]
				FROM
				    [dbo].[tblCustomerOpinion] O,
				    #PageIndex PageIndex
				WHERE
				    PageIndex.IndexId > @PageLowerBound
					AND O.[Id] = PageIndex.[Id]
				ORDER BY
				    PageIndex.IndexId
				
				-- get row count
				SET @SQL = 'SELECT COUNT(*) AS TotalRowCount'
				SET @SQL = @SQL + ' FROM [dbo].[tblCustomerOpinion]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				EXEC sp_executesql @SQL
			
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblCustomerOpinion_Insert procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblCustomerOpinion_Insert') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblCustomerOpinion_Insert
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Inserts a record into the tblCustomerOpinion table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblCustomerOpinion_Insert
(

	@Id int    OUTPUT,

	@Date datetime   ,

	@Fullname nvarchar (128)  ,

	@Email nvarchar (128)  ,

	@Phone varchar (32)  ,

	@Address nvarchar (128)  ,

	@Answer ntext   ,

	@Opinion ntext   ,

	@Title nvarchar (128)  ,

	@Code varchar (128)  ,

	@LanguageId int   ,

	@IsActive bit   ,

	@Type char (1)  ,

	@Tags nvarchar (1024)  
)
AS


				
				INSERT INTO [dbo].[tblCustomerOpinion]
					(
					[Date]
					,[Fullname]
					,[Email]
					,[Phone]
					,[Address]
					,[Answer]
					,[Opinion]
					,[Title]
					,[Code]
					,[LanguageId]
					,[IsActive]
					,[Type]
					,[Tags]
					)
				VALUES
					(
					@Date
					,@Fullname
					,@Email
					,@Phone
					,@Address
					,@Answer
					,@Opinion
					,@Title
					,@Code
					,@LanguageId
					,@IsActive
					,@Type
					,@Tags
					)
				
				-- Get the identity value
				SET @Id = SCOPE_IDENTITY()
									
							
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblCustomerOpinion_Update procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblCustomerOpinion_Update') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblCustomerOpinion_Update
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Updates a record in the tblCustomerOpinion table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblCustomerOpinion_Update
(

	@Id int   ,

	@Date datetime   ,

	@Fullname nvarchar (128)  ,

	@Email nvarchar (128)  ,

	@Phone varchar (32)  ,

	@Address nvarchar (128)  ,

	@Answer ntext   ,

	@Opinion ntext   ,

	@Title nvarchar (128)  ,

	@Code varchar (128)  ,

	@LanguageId int   ,

	@IsActive bit   ,

	@Type char (1)  ,

	@Tags nvarchar (1024)  
)
AS


				
				
				-- Modify the updatable columns
				UPDATE
					[dbo].[tblCustomerOpinion]
				SET
					[Date] = @Date
					,[Fullname] = @Fullname
					,[Email] = @Email
					,[Phone] = @Phone
					,[Address] = @Address
					,[Answer] = @Answer
					,[Opinion] = @Opinion
					,[Title] = @Title
					,[Code] = @Code
					,[LanguageId] = @LanguageId
					,[IsActive] = @IsActive
					,[Type] = @Type
					,[Tags] = @Tags
				WHERE
[Id] = @Id 
				
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblCustomerOpinion_Delete procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblCustomerOpinion_Delete') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblCustomerOpinion_Delete
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Deletes a record in the tblCustomerOpinion table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblCustomerOpinion_Delete
(

	@Id int   
)
AS


				DELETE FROM [dbo].[tblCustomerOpinion] WITH (ROWLOCK) 
				WHERE
					[Id] = @Id
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblCustomerOpinion_GetByLanguageId procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblCustomerOpinion_GetByLanguageId') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblCustomerOpinion_GetByLanguageId
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Select records from the tblCustomerOpinion table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblCustomerOpinion_GetByLanguageId
(

	@LanguageId int   
)
AS


				SET ANSI_NULLS OFF
				
				SELECT
					[Id],
					[Date],
					[Fullname],
					[Email],
					[Phone],
					[Address],
					[Answer],
					[Opinion],
					[Title],
					[Code],
					[LanguageId],
					[IsActive],
					[Type],
					[Tags]
				FROM
					[dbo].[tblCustomerOpinion]
				WHERE
					[LanguageId] = @LanguageId
				
				SELECT @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblCustomerOpinion_GetById procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblCustomerOpinion_GetById') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblCustomerOpinion_GetById
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Select records from the tblCustomerOpinion table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblCustomerOpinion_GetById
(

	@Id int   
)
AS


				SELECT
					[Id],
					[Date],
					[Fullname],
					[Email],
					[Phone],
					[Address],
					[Answer],
					[Opinion],
					[Title],
					[Code],
					[LanguageId],
					[IsActive],
					[Type],
					[Tags]
				FROM
					[dbo].[tblCustomerOpinion]
				WHERE
					[Id] = @Id
				SELECT @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblCustomerOpinion_GetByCode procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblCustomerOpinion_GetByCode') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblCustomerOpinion_GetByCode
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Select records from the tblCustomerOpinion table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblCustomerOpinion_GetByCode
(

	@Code varchar (128)  
)
AS


				SELECT
					[Id],
					[Date],
					[Fullname],
					[Email],
					[Phone],
					[Address],
					[Answer],
					[Opinion],
					[Title],
					[Code],
					[LanguageId],
					[IsActive],
					[Type],
					[Tags]
				FROM
					[dbo].[tblCustomerOpinion]
				WHERE
					[Code] = @Code
				SELECT @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblCustomerOpinion_Find procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblCustomerOpinion_Find') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblCustomerOpinion_Find
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Finds records in the tblCustomerOpinion table passing nullable parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblCustomerOpinion_Find
(

	@SearchUsingOR bit   = null ,

	@Id int   = null ,

	@Date datetime   = null ,

	@Fullname nvarchar (128)  = null ,

	@Email nvarchar (128)  = null ,

	@Phone varchar (32)  = null ,

	@Address nvarchar (128)  = null ,

	@Answer ntext   = null ,

	@Opinion ntext   = null ,

	@Title nvarchar (128)  = null ,

	@Code varchar (128)  = null ,

	@LanguageId int   = null ,

	@IsActive bit   = null ,

	@Type char (1)  = null ,

	@Tags nvarchar (1024)  = null 
)
AS


				
  IF ISNULL(@SearchUsingOR, 0) <> 1
  BEGIN
    SELECT
	  [Id]
	, [Date]
	, [Fullname]
	, [Email]
	, [Phone]
	, [Address]
	, [Answer]
	, [Opinion]
	, [Title]
	, [Code]
	, [LanguageId]
	, [IsActive]
	, [Type]
	, [Tags]
    FROM
	[dbo].[tblCustomerOpinion]
    WHERE 
	 ([Id] = @Id OR @Id IS NULL)
	AND ([Date] = @Date OR @Date IS NULL)
	AND ([Fullname] = @Fullname OR @Fullname IS NULL)
	AND ([Email] = @Email OR @Email IS NULL)
	AND ([Phone] = @Phone OR @Phone IS NULL)
	AND ([Address] = @Address OR @Address IS NULL)
	AND ([Title] = @Title OR @Title IS NULL)
	AND ([Code] = @Code OR @Code IS NULL)
	AND ([LanguageId] = @LanguageId OR @LanguageId IS NULL)
	AND ([IsActive] = @IsActive OR @IsActive IS NULL)
	AND ([Type] = @Type OR @Type IS NULL)
	AND ([Tags] = @Tags OR @Tags IS NULL)
						
  END
  ELSE
  BEGIN
    SELECT
	  [Id]
	, [Date]
	, [Fullname]
	, [Email]
	, [Phone]
	, [Address]
	, [Answer]
	, [Opinion]
	, [Title]
	, [Code]
	, [LanguageId]
	, [IsActive]
	, [Type]
	, [Tags]
    FROM
	[dbo].[tblCustomerOpinion]
    WHERE 
	 ([Id] = @Id AND @Id is not null)
	OR ([Date] = @Date AND @Date is not null)
	OR ([Fullname] = @Fullname AND @Fullname is not null)
	OR ([Email] = @Email AND @Email is not null)
	OR ([Phone] = @Phone AND @Phone is not null)
	OR ([Address] = @Address AND @Address is not null)
	OR ([Title] = @Title AND @Title is not null)
	OR ([Code] = @Code AND @Code is not null)
	OR ([LanguageId] = @LanguageId AND @LanguageId is not null)
	OR ([IsActive] = @IsActive AND @IsActive is not null)
	OR ([Type] = @Type AND @Type is not null)
	OR ([Tags] = @Tags AND @Tags is not null)
	SELECT @@ROWCOUNT			
  END
				

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblGroup_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblGroup_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblGroup_Get_List
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Gets all records from the tblGroup table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblGroup_Get_List

AS


				
				SELECT
					[Id],
					[Name],
					[Description],
					[IsActive]
				FROM
					[dbo].[tblGroup]
					
				SELECT @@ROWCOUNT
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblGroup_GetPaged procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblGroup_GetPaged') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblGroup_GetPaged
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Gets records from the tblGroup table passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblGroup_GetPaged
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				
				BEGIN
				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				-- Create a temp table to store the select results
				CREATE TABLE #PageIndex
				(
				    [IndexId] int IDENTITY (1, 1) NOT NULL,
				    [Id] int 
				)
				
				-- Insert into the temp table
				DECLARE @SQL AS nvarchar(4000)
				SET @SQL = 'INSERT INTO #PageIndex ([Id])'
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + CONVERT(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' [Id]'
				SET @SQL = @SQL + ' FROM [dbo].[tblGroup]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				IF LEN(@OrderBy) > 0
				BEGIN
					SET @SQL = @SQL + ' ORDER BY ' + @OrderBy
				END
				
				-- Populate the temp table
				EXEC sp_executesql @SQL

				-- Return paged results
				SELECT O.[Id], O.[Name], O.[Description], O.[IsActive]
				FROM
				    [dbo].[tblGroup] O,
				    #PageIndex PageIndex
				WHERE
				    PageIndex.IndexId > @PageLowerBound
					AND O.[Id] = PageIndex.[Id]
				ORDER BY
				    PageIndex.IndexId
				
				-- get row count
				SET @SQL = 'SELECT COUNT(*) AS TotalRowCount'
				SET @SQL = @SQL + ' FROM [dbo].[tblGroup]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				EXEC sp_executesql @SQL
			
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblGroup_Insert procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblGroup_Insert') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblGroup_Insert
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Inserts a record into the tblGroup table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblGroup_Insert
(

	@Id int    OUTPUT,

	@Name nvarchar (128)  ,

	@Description nvarchar (256)  ,

	@IsActive bit   
)
AS


				
				INSERT INTO [dbo].[tblGroup]
					(
					[Name]
					,[Description]
					,[IsActive]
					)
				VALUES
					(
					@Name
					,@Description
					,@IsActive
					)
				
				-- Get the identity value
				SET @Id = SCOPE_IDENTITY()
									
							
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblGroup_Update procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblGroup_Update') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblGroup_Update
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Updates a record in the tblGroup table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblGroup_Update
(

	@Id int   ,

	@Name nvarchar (128)  ,

	@Description nvarchar (256)  ,

	@IsActive bit   
)
AS


				
				
				-- Modify the updatable columns
				UPDATE
					[dbo].[tblGroup]
				SET
					[Name] = @Name
					,[Description] = @Description
					,[IsActive] = @IsActive
				WHERE
[Id] = @Id 
				
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblGroup_Delete procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblGroup_Delete') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblGroup_Delete
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Deletes a record in the tblGroup table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblGroup_Delete
(

	@Id int   
)
AS


				DELETE FROM [dbo].[tblGroup] WITH (ROWLOCK) 
				WHERE
					[Id] = @Id
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblGroup_GetById procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblGroup_GetById') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblGroup_GetById
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Select records from the tblGroup table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblGroup_GetById
(

	@Id int   
)
AS


				SELECT
					[Id],
					[Name],
					[Description],
					[IsActive]
				FROM
					[dbo].[tblGroup]
				WHERE
					[Id] = @Id
				SELECT @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblGroup_Find procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblGroup_Find') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblGroup_Find
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Finds records in the tblGroup table passing nullable parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblGroup_Find
(

	@SearchUsingOR bit   = null ,

	@Id int   = null ,

	@Name nvarchar (128)  = null ,

	@Description nvarchar (256)  = null ,

	@IsActive bit   = null 
)
AS


				
  IF ISNULL(@SearchUsingOR, 0) <> 1
  BEGIN
    SELECT
	  [Id]
	, [Name]
	, [Description]
	, [IsActive]
    FROM
	[dbo].[tblGroup]
    WHERE 
	 ([Id] = @Id OR @Id IS NULL)
	AND ([Name] = @Name OR @Name IS NULL)
	AND ([Description] = @Description OR @Description IS NULL)
	AND ([IsActive] = @IsActive OR @IsActive IS NULL)
						
  END
  ELSE
  BEGIN
    SELECT
	  [Id]
	, [Name]
	, [Description]
	, [IsActive]
    FROM
	[dbo].[tblGroup]
    WHERE 
	 ([Id] = @Id AND @Id is not null)
	OR ([Name] = @Name AND @Name is not null)
	OR ([Description] = @Description AND @Description is not null)
	OR ([IsActive] = @IsActive AND @IsActive is not null)
	SELECT @@ROWCOUNT			
  END
				

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblContactInfo_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblContactInfo_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblContactInfo_Get_List
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Gets all records from the tblContactInfo table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblContactInfo_Get_List

AS


				
				SELECT
					[Id],
					[Name],
					[Type],
					[ImagePath],
					[Value],
					[LanguageId],
					[IsShow]
				FROM
					[dbo].[tblContactInfo]
					
				SELECT @@ROWCOUNT
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblContactInfo_GetPaged procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblContactInfo_GetPaged') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblContactInfo_GetPaged
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Gets records from the tblContactInfo table passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblContactInfo_GetPaged
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				
				BEGIN
				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				-- Create a temp table to store the select results
				CREATE TABLE #PageIndex
				(
				    [IndexId] int IDENTITY (1, 1) NOT NULL,
				    [Id] int 
				)
				
				-- Insert into the temp table
				DECLARE @SQL AS nvarchar(4000)
				SET @SQL = 'INSERT INTO #PageIndex ([Id])'
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + CONVERT(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' [Id]'
				SET @SQL = @SQL + ' FROM [dbo].[tblContactInfo]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				IF LEN(@OrderBy) > 0
				BEGIN
					SET @SQL = @SQL + ' ORDER BY ' + @OrderBy
				END
				
				-- Populate the temp table
				EXEC sp_executesql @SQL

				-- Return paged results
				SELECT O.[Id], O.[Name], O.[Type], O.[ImagePath], O.[Value], O.[LanguageId], O.[IsShow]
				FROM
				    [dbo].[tblContactInfo] O,
				    #PageIndex PageIndex
				WHERE
				    PageIndex.IndexId > @PageLowerBound
					AND O.[Id] = PageIndex.[Id]
				ORDER BY
				    PageIndex.IndexId
				
				-- get row count
				SET @SQL = 'SELECT COUNT(*) AS TotalRowCount'
				SET @SQL = @SQL + ' FROM [dbo].[tblContactInfo]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				EXEC sp_executesql @SQL
			
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblContactInfo_Insert procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblContactInfo_Insert') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblContactInfo_Insert
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Inserts a record into the tblContactInfo table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblContactInfo_Insert
(

	@Id int    OUTPUT,

	@Name nvarchar (512)  ,

	@Type char (2)  ,

	@ImagePath nvarchar (256)  ,

	@Value ntext   ,

	@LanguageId int   ,

	@IsShow bit   
)
AS


				
				INSERT INTO [dbo].[tblContactInfo]
					(
					[Name]
					,[Type]
					,[ImagePath]
					,[Value]
					,[LanguageId]
					,[IsShow]
					)
				VALUES
					(
					@Name
					,@Type
					,@ImagePath
					,@Value
					,@LanguageId
					,@IsShow
					)
				
				-- Get the identity value
				SET @Id = SCOPE_IDENTITY()
									
							
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblContactInfo_Update procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblContactInfo_Update') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblContactInfo_Update
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Updates a record in the tblContactInfo table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblContactInfo_Update
(

	@Id int   ,

	@Name nvarchar (512)  ,

	@Type char (2)  ,

	@ImagePath nvarchar (256)  ,

	@Value ntext   ,

	@LanguageId int   ,

	@IsShow bit   
)
AS


				
				
				-- Modify the updatable columns
				UPDATE
					[dbo].[tblContactInfo]
				SET
					[Name] = @Name
					,[Type] = @Type
					,[ImagePath] = @ImagePath
					,[Value] = @Value
					,[LanguageId] = @LanguageId
					,[IsShow] = @IsShow
				WHERE
[Id] = @Id 
				
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblContactInfo_Delete procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblContactInfo_Delete') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblContactInfo_Delete
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Deletes a record in the tblContactInfo table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblContactInfo_Delete
(

	@Id int   
)
AS


				DELETE FROM [dbo].[tblContactInfo] WITH (ROWLOCK) 
				WHERE
					[Id] = @Id
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblContactInfo_GetByLanguageId procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblContactInfo_GetByLanguageId') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblContactInfo_GetByLanguageId
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Select records from the tblContactInfo table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblContactInfo_GetByLanguageId
(

	@LanguageId int   
)
AS


				SET ANSI_NULLS OFF
				
				SELECT
					[Id],
					[Name],
					[Type],
					[ImagePath],
					[Value],
					[LanguageId],
					[IsShow]
				FROM
					[dbo].[tblContactInfo]
				WHERE
					[LanguageId] = @LanguageId
				
				SELECT @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblContactInfo_GetById procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblContactInfo_GetById') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblContactInfo_GetById
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Select records from the tblContactInfo table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblContactInfo_GetById
(

	@Id int   
)
AS


				SELECT
					[Id],
					[Name],
					[Type],
					[ImagePath],
					[Value],
					[LanguageId],
					[IsShow]
				FROM
					[dbo].[tblContactInfo]
				WHERE
					[Id] = @Id
				SELECT @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblContactInfo_Find procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblContactInfo_Find') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblContactInfo_Find
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Finds records in the tblContactInfo table passing nullable parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblContactInfo_Find
(

	@SearchUsingOR bit   = null ,

	@Id int   = null ,

	@Name nvarchar (512)  = null ,

	@Type char (2)  = null ,

	@ImagePath nvarchar (256)  = null ,

	@Value ntext   = null ,

	@LanguageId int   = null ,

	@IsShow bit   = null 
)
AS


				
  IF ISNULL(@SearchUsingOR, 0) <> 1
  BEGIN
    SELECT
	  [Id]
	, [Name]
	, [Type]
	, [ImagePath]
	, [Value]
	, [LanguageId]
	, [IsShow]
    FROM
	[dbo].[tblContactInfo]
    WHERE 
	 ([Id] = @Id OR @Id IS NULL)
	AND ([Name] = @Name OR @Name IS NULL)
	AND ([Type] = @Type OR @Type IS NULL)
	AND ([ImagePath] = @ImagePath OR @ImagePath IS NULL)
	AND ([LanguageId] = @LanguageId OR @LanguageId IS NULL)
	AND ([IsShow] = @IsShow OR @IsShow IS NULL)
						
  END
  ELSE
  BEGIN
    SELECT
	  [Id]
	, [Name]
	, [Type]
	, [ImagePath]
	, [Value]
	, [LanguageId]
	, [IsShow]
    FROM
	[dbo].[tblContactInfo]
    WHERE 
	 ([Id] = @Id AND @Id is not null)
	OR ([Name] = @Name AND @Name is not null)
	OR ([Type] = @Type AND @Type is not null)
	OR ([ImagePath] = @ImagePath AND @ImagePath is not null)
	OR ([LanguageId] = @LanguageId AND @LanguageId is not null)
	OR ([IsShow] = @IsShow AND @IsShow is not null)
	SELECT @@ROWCOUNT			
  END
				

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblFeatureList_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblFeatureList_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblFeatureList_Get_List
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Gets all records from the tblFeatureList table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblFeatureList_Get_List

AS


				
				SELECT
					[Id],
					[Name],
					[IsUse]
				FROM
					[dbo].[tblFeatureList]
					
				SELECT @@ROWCOUNT
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblFeatureList_GetPaged procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblFeatureList_GetPaged') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblFeatureList_GetPaged
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Gets records from the tblFeatureList table passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblFeatureList_GetPaged
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				
				BEGIN
				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				-- Create a temp table to store the select results
				CREATE TABLE #PageIndex
				(
				    [IndexId] int IDENTITY (1, 1) NOT NULL,
				    [Id] int 
				)
				
				-- Insert into the temp table
				DECLARE @SQL AS nvarchar(4000)
				SET @SQL = 'INSERT INTO #PageIndex ([Id])'
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + CONVERT(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' [Id]'
				SET @SQL = @SQL + ' FROM [dbo].[tblFeatureList]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				IF LEN(@OrderBy) > 0
				BEGIN
					SET @SQL = @SQL + ' ORDER BY ' + @OrderBy
				END
				
				-- Populate the temp table
				EXEC sp_executesql @SQL

				-- Return paged results
				SELECT O.[Id], O.[Name], O.[IsUse]
				FROM
				    [dbo].[tblFeatureList] O,
				    #PageIndex PageIndex
				WHERE
				    PageIndex.IndexId > @PageLowerBound
					AND O.[Id] = PageIndex.[Id]
				ORDER BY
				    PageIndex.IndexId
				
				-- get row count
				SET @SQL = 'SELECT COUNT(*) AS TotalRowCount'
				SET @SQL = @SQL + ' FROM [dbo].[tblFeatureList]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				EXEC sp_executesql @SQL
			
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblFeatureList_Insert procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblFeatureList_Insert') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblFeatureList_Insert
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Inserts a record into the tblFeatureList table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblFeatureList_Insert
(

	@Id int    OUTPUT,

	@Name nvarchar (256)  ,

	@IsUse bit   
)
AS


				
				INSERT INTO [dbo].[tblFeatureList]
					(
					[Name]
					,[IsUse]
					)
				VALUES
					(
					@Name
					,@IsUse
					)
				
				-- Get the identity value
				SET @Id = SCOPE_IDENTITY()
									
							
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblFeatureList_Update procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblFeatureList_Update') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblFeatureList_Update
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Updates a record in the tblFeatureList table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblFeatureList_Update
(

	@Id int   ,

	@Name nvarchar (256)  ,

	@IsUse bit   
)
AS


				
				
				-- Modify the updatable columns
				UPDATE
					[dbo].[tblFeatureList]
				SET
					[Name] = @Name
					,[IsUse] = @IsUse
				WHERE
[Id] = @Id 
				
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblFeatureList_Delete procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblFeatureList_Delete') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblFeatureList_Delete
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Deletes a record in the tblFeatureList table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblFeatureList_Delete
(

	@Id int   
)
AS


				DELETE FROM [dbo].[tblFeatureList] WITH (ROWLOCK) 
				WHERE
					[Id] = @Id
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblFeatureList_GetById procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblFeatureList_GetById') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblFeatureList_GetById
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Select records from the tblFeatureList table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblFeatureList_GetById
(

	@Id int   
)
AS


				SELECT
					[Id],
					[Name],
					[IsUse]
				FROM
					[dbo].[tblFeatureList]
				WHERE
					[Id] = @Id
				SELECT @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblFeatureList_Find procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblFeatureList_Find') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblFeatureList_Find
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Finds records in the tblFeatureList table passing nullable parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblFeatureList_Find
(

	@SearchUsingOR bit   = null ,

	@Id int   = null ,

	@Name nvarchar (256)  = null ,

	@IsUse bit   = null 
)
AS


				
  IF ISNULL(@SearchUsingOR, 0) <> 1
  BEGIN
    SELECT
	  [Id]
	, [Name]
	, [IsUse]
    FROM
	[dbo].[tblFeatureList]
    WHERE 
	 ([Id] = @Id OR @Id IS NULL)
	AND ([Name] = @Name OR @Name IS NULL)
	AND ([IsUse] = @IsUse OR @IsUse IS NULL)
						
  END
  ELSE
  BEGIN
    SELECT
	  [Id]
	, [Name]
	, [IsUse]
    FROM
	[dbo].[tblFeatureList]
    WHERE 
	 ([Id] = @Id AND @Id is not null)
	OR ([Name] = @Name AND @Name is not null)
	OR ([IsUse] = @IsUse AND @IsUse is not null)
	SELECT @@ROWCOUNT			
  END
				

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblMultimedia_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblMultimedia_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblMultimedia_Get_List
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Gets all records from the tblMultimedia table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblMultimedia_Get_List

AS


				
				SELECT
					[Id],
					[Name],
					[Path],
					[AlbumId],
					[Status],
					[PostedDate],
					[PostedBy],
					[Type]
				FROM
					[dbo].[tblMultimedia]
					
				SELECT @@ROWCOUNT
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblMultimedia_GetPaged procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblMultimedia_GetPaged') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblMultimedia_GetPaged
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Gets records from the tblMultimedia table passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblMultimedia_GetPaged
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				
				BEGIN
				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				-- Create a temp table to store the select results
				CREATE TABLE #PageIndex
				(
				    [IndexId] int IDENTITY (1, 1) NOT NULL,
				    [Id] int 
				)
				
				-- Insert into the temp table
				DECLARE @SQL AS nvarchar(4000)
				SET @SQL = 'INSERT INTO #PageIndex ([Id])'
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + CONVERT(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' [Id]'
				SET @SQL = @SQL + ' FROM [dbo].[tblMultimedia]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				IF LEN(@OrderBy) > 0
				BEGIN
					SET @SQL = @SQL + ' ORDER BY ' + @OrderBy
				END
				
				-- Populate the temp table
				EXEC sp_executesql @SQL

				-- Return paged results
				SELECT O.[Id], O.[Name], O.[Path], O.[AlbumId], O.[Status], O.[PostedDate], O.[PostedBy], O.[Type]
				FROM
				    [dbo].[tblMultimedia] O,
				    #PageIndex PageIndex
				WHERE
				    PageIndex.IndexId > @PageLowerBound
					AND O.[Id] = PageIndex.[Id]
				ORDER BY
				    PageIndex.IndexId
				
				-- get row count
				SET @SQL = 'SELECT COUNT(*) AS TotalRowCount'
				SET @SQL = @SQL + ' FROM [dbo].[tblMultimedia]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				EXEC sp_executesql @SQL
			
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblMultimedia_Insert procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblMultimedia_Insert') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblMultimedia_Insert
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Inserts a record into the tblMultimedia table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblMultimedia_Insert
(

	@Id int    OUTPUT,

	@Name nvarchar (128)  ,

	@Path nvarchar (256)  ,

	@AlbumId int   ,

	@Status char (1)  ,

	@PostedDate datetime   ,

	@PostedBy varchar (50)  ,

	@Type char (1)  
)
AS


				
				INSERT INTO [dbo].[tblMultimedia]
					(
					[Name]
					,[Path]
					,[AlbumId]
					,[Status]
					,[PostedDate]
					,[PostedBy]
					,[Type]
					)
				VALUES
					(
					@Name
					,@Path
					,@AlbumId
					,@Status
					,@PostedDate
					,@PostedBy
					,@Type
					)
				
				-- Get the identity value
				SET @Id = SCOPE_IDENTITY()
									
							
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblMultimedia_Update procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblMultimedia_Update') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblMultimedia_Update
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Updates a record in the tblMultimedia table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblMultimedia_Update
(

	@Id int   ,

	@Name nvarchar (128)  ,

	@Path nvarchar (256)  ,

	@AlbumId int   ,

	@Status char (1)  ,

	@PostedDate datetime   ,

	@PostedBy varchar (50)  ,

	@Type char (1)  
)
AS


				
				
				-- Modify the updatable columns
				UPDATE
					[dbo].[tblMultimedia]
				SET
					[Name] = @Name
					,[Path] = @Path
					,[AlbumId] = @AlbumId
					,[Status] = @Status
					,[PostedDate] = @PostedDate
					,[PostedBy] = @PostedBy
					,[Type] = @Type
				WHERE
[Id] = @Id 
				
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblMultimedia_Delete procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblMultimedia_Delete') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblMultimedia_Delete
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Deletes a record in the tblMultimedia table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblMultimedia_Delete
(

	@Id int   
)
AS


				DELETE FROM [dbo].[tblMultimedia] WITH (ROWLOCK) 
				WHERE
					[Id] = @Id
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblMultimedia_GetByAlbumId procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblMultimedia_GetByAlbumId') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblMultimedia_GetByAlbumId
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Select records from the tblMultimedia table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblMultimedia_GetByAlbumId
(

	@AlbumId int   
)
AS


				SET ANSI_NULLS OFF
				
				SELECT
					[Id],
					[Name],
					[Path],
					[AlbumId],
					[Status],
					[PostedDate],
					[PostedBy],
					[Type]
				FROM
					[dbo].[tblMultimedia]
				WHERE
					[AlbumId] = @AlbumId
				
				SELECT @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblMultimedia_GetById procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblMultimedia_GetById') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblMultimedia_GetById
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Select records from the tblMultimedia table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblMultimedia_GetById
(

	@Id int   
)
AS


				SELECT
					[Id],
					[Name],
					[Path],
					[AlbumId],
					[Status],
					[PostedDate],
					[PostedBy],
					[Type]
				FROM
					[dbo].[tblMultimedia]
				WHERE
					[Id] = @Id
				SELECT @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblMultimedia_Find procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblMultimedia_Find') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblMultimedia_Find
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Finds records in the tblMultimedia table passing nullable parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblMultimedia_Find
(

	@SearchUsingOR bit   = null ,

	@Id int   = null ,

	@Name nvarchar (128)  = null ,

	@Path nvarchar (256)  = null ,

	@AlbumId int   = null ,

	@Status char (1)  = null ,

	@PostedDate datetime   = null ,

	@PostedBy varchar (50)  = null ,

	@Type char (1)  = null 
)
AS


				
  IF ISNULL(@SearchUsingOR, 0) <> 1
  BEGIN
    SELECT
	  [Id]
	, [Name]
	, [Path]
	, [AlbumId]
	, [Status]
	, [PostedDate]
	, [PostedBy]
	, [Type]
    FROM
	[dbo].[tblMultimedia]
    WHERE 
	 ([Id] = @Id OR @Id IS NULL)
	AND ([Name] = @Name OR @Name IS NULL)
	AND ([Path] = @Path OR @Path IS NULL)
	AND ([AlbumId] = @AlbumId OR @AlbumId IS NULL)
	AND ([Status] = @Status OR @Status IS NULL)
	AND ([PostedDate] = @PostedDate OR @PostedDate IS NULL)
	AND ([PostedBy] = @PostedBy OR @PostedBy IS NULL)
	AND ([Type] = @Type OR @Type IS NULL)
						
  END
  ELSE
  BEGIN
    SELECT
	  [Id]
	, [Name]
	, [Path]
	, [AlbumId]
	, [Status]
	, [PostedDate]
	, [PostedBy]
	, [Type]
    FROM
	[dbo].[tblMultimedia]
    WHERE 
	 ([Id] = @Id AND @Id is not null)
	OR ([Name] = @Name AND @Name is not null)
	OR ([Path] = @Path AND @Path is not null)
	OR ([AlbumId] = @AlbumId AND @AlbumId is not null)
	OR ([Status] = @Status AND @Status is not null)
	OR ([PostedDate] = @PostedDate AND @PostedDate is not null)
	OR ([PostedBy] = @PostedBy AND @PostedBy is not null)
	OR ([Type] = @Type AND @Type is not null)
	SELECT @@ROWCOUNT			
  END
				

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblAlbumLocale_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblAlbumLocale_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblAlbumLocale_Get_List
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Gets all records from the tblAlbumLocale table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblAlbumLocale_Get_List

AS


				
				SELECT
					[Id],
					[LanguageId],
					[AlbumId],
					[Name],
					[Description]
				FROM
					[dbo].[tblAlbumLocale]
					
				SELECT @@ROWCOUNT
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblAlbumLocale_GetPaged procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblAlbumLocale_GetPaged') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblAlbumLocale_GetPaged
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Gets records from the tblAlbumLocale table passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblAlbumLocale_GetPaged
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				
				BEGIN
				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				-- Create a temp table to store the select results
				CREATE TABLE #PageIndex
				(
				    [IndexId] int IDENTITY (1, 1) NOT NULL,
				    [Id] int 
				)
				
				-- Insert into the temp table
				DECLARE @SQL AS nvarchar(4000)
				SET @SQL = 'INSERT INTO #PageIndex ([Id])'
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + CONVERT(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' [Id]'
				SET @SQL = @SQL + ' FROM [dbo].[tblAlbumLocale]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				IF LEN(@OrderBy) > 0
				BEGIN
					SET @SQL = @SQL + ' ORDER BY ' + @OrderBy
				END
				
				-- Populate the temp table
				EXEC sp_executesql @SQL

				-- Return paged results
				SELECT O.[Id], O.[LanguageId], O.[AlbumId], O.[Name], O.[Description]
				FROM
				    [dbo].[tblAlbumLocale] O,
				    #PageIndex PageIndex
				WHERE
				    PageIndex.IndexId > @PageLowerBound
					AND O.[Id] = PageIndex.[Id]
				ORDER BY
				    PageIndex.IndexId
				
				-- get row count
				SET @SQL = 'SELECT COUNT(*) AS TotalRowCount'
				SET @SQL = @SQL + ' FROM [dbo].[tblAlbumLocale]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				EXEC sp_executesql @SQL
			
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblAlbumLocale_Insert procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblAlbumLocale_Insert') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblAlbumLocale_Insert
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Inserts a record into the tblAlbumLocale table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblAlbumLocale_Insert
(

	@Id int    OUTPUT,

	@LanguageId int   ,

	@AlbumId int   ,

	@Name nvarchar (128)  ,

	@Description nvarchar (1024)  
)
AS


				
				INSERT INTO [dbo].[tblAlbumLocale]
					(
					[LanguageId]
					,[AlbumId]
					,[Name]
					,[Description]
					)
				VALUES
					(
					@LanguageId
					,@AlbumId
					,@Name
					,@Description
					)
				
				-- Get the identity value
				SET @Id = SCOPE_IDENTITY()
									
							
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblAlbumLocale_Update procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblAlbumLocale_Update') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblAlbumLocale_Update
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Updates a record in the tblAlbumLocale table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblAlbumLocale_Update
(

	@Id int   ,

	@LanguageId int   ,

	@AlbumId int   ,

	@Name nvarchar (128)  ,

	@Description nvarchar (1024)  
)
AS


				
				
				-- Modify the updatable columns
				UPDATE
					[dbo].[tblAlbumLocale]
				SET
					[LanguageId] = @LanguageId
					,[AlbumId] = @AlbumId
					,[Name] = @Name
					,[Description] = @Description
				WHERE
[Id] = @Id 
				
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblAlbumLocale_Delete procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblAlbumLocale_Delete') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblAlbumLocale_Delete
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Deletes a record in the tblAlbumLocale table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblAlbumLocale_Delete
(

	@Id int   
)
AS


				DELETE FROM [dbo].[tblAlbumLocale] WITH (ROWLOCK) 
				WHERE
					[Id] = @Id
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblAlbumLocale_GetByAlbumId procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblAlbumLocale_GetByAlbumId') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblAlbumLocale_GetByAlbumId
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Select records from the tblAlbumLocale table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblAlbumLocale_GetByAlbumId
(

	@AlbumId int   
)
AS


				SET ANSI_NULLS OFF
				
				SELECT
					[Id],
					[LanguageId],
					[AlbumId],
					[Name],
					[Description]
				FROM
					[dbo].[tblAlbumLocale]
				WHERE
					[AlbumId] = @AlbumId
				
				SELECT @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblAlbumLocale_GetByLanguageId procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblAlbumLocale_GetByLanguageId') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblAlbumLocale_GetByLanguageId
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Select records from the tblAlbumLocale table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblAlbumLocale_GetByLanguageId
(

	@LanguageId int   
)
AS


				SET ANSI_NULLS OFF
				
				SELECT
					[Id],
					[LanguageId],
					[AlbumId],
					[Name],
					[Description]
				FROM
					[dbo].[tblAlbumLocale]
				WHERE
					[LanguageId] = @LanguageId
				
				SELECT @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblAlbumLocale_GetById procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblAlbumLocale_GetById') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblAlbumLocale_GetById
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Select records from the tblAlbumLocale table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblAlbumLocale_GetById
(

	@Id int   
)
AS


				SELECT
					[Id],
					[LanguageId],
					[AlbumId],
					[Name],
					[Description]
				FROM
					[dbo].[tblAlbumLocale]
				WHERE
					[Id] = @Id
				SELECT @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblAlbumLocale_Find procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblAlbumLocale_Find') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblAlbumLocale_Find
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Finds records in the tblAlbumLocale table passing nullable parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblAlbumLocale_Find
(

	@SearchUsingOR bit   = null ,

	@Id int   = null ,

	@LanguageId int   = null ,

	@AlbumId int   = null ,

	@Name nvarchar (128)  = null ,

	@Description nvarchar (1024)  = null 
)
AS


				
  IF ISNULL(@SearchUsingOR, 0) <> 1
  BEGIN
    SELECT
	  [Id]
	, [LanguageId]
	, [AlbumId]
	, [Name]
	, [Description]
    FROM
	[dbo].[tblAlbumLocale]
    WHERE 
	 ([Id] = @Id OR @Id IS NULL)
	AND ([LanguageId] = @LanguageId OR @LanguageId IS NULL)
	AND ([AlbumId] = @AlbumId OR @AlbumId IS NULL)
	AND ([Name] = @Name OR @Name IS NULL)
	AND ([Description] = @Description OR @Description IS NULL)
						
  END
  ELSE
  BEGIN
    SELECT
	  [Id]
	, [LanguageId]
	, [AlbumId]
	, [Name]
	, [Description]
    FROM
	[dbo].[tblAlbumLocale]
    WHERE 
	 ([Id] = @Id AND @Id is not null)
	OR ([LanguageId] = @LanguageId AND @LanguageId is not null)
	OR ([AlbumId] = @AlbumId AND @AlbumId is not null)
	OR ([Name] = @Name AND @Name is not null)
	OR ([Description] = @Description AND @Description is not null)
	SELECT @@ROWCOUNT			
  END
				

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblFeatureListLocale_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblFeatureListLocale_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblFeatureListLocale_Get_List
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Gets all records from the tblFeatureListLocale table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblFeatureListLocale_Get_List

AS


				
				SELECT
					[Id],
					[LanguageId],
					[FeatureId],
					[Name]
				FROM
					[dbo].[tblFeatureListLocale]
					
				SELECT @@ROWCOUNT
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblFeatureListLocale_GetPaged procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblFeatureListLocale_GetPaged') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblFeatureListLocale_GetPaged
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Gets records from the tblFeatureListLocale table passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblFeatureListLocale_GetPaged
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				
				BEGIN
				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				-- Create a temp table to store the select results
				CREATE TABLE #PageIndex
				(
				    [IndexId] int IDENTITY (1, 1) NOT NULL,
				    [Id] int 
				)
				
				-- Insert into the temp table
				DECLARE @SQL AS nvarchar(4000)
				SET @SQL = 'INSERT INTO #PageIndex ([Id])'
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + CONVERT(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' [Id]'
				SET @SQL = @SQL + ' FROM [dbo].[tblFeatureListLocale]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				IF LEN(@OrderBy) > 0
				BEGIN
					SET @SQL = @SQL + ' ORDER BY ' + @OrderBy
				END
				
				-- Populate the temp table
				EXEC sp_executesql @SQL

				-- Return paged results
				SELECT O.[Id], O.[LanguageId], O.[FeatureId], O.[Name]
				FROM
				    [dbo].[tblFeatureListLocale] O,
				    #PageIndex PageIndex
				WHERE
				    PageIndex.IndexId > @PageLowerBound
					AND O.[Id] = PageIndex.[Id]
				ORDER BY
				    PageIndex.IndexId
				
				-- get row count
				SET @SQL = 'SELECT COUNT(*) AS TotalRowCount'
				SET @SQL = @SQL + ' FROM [dbo].[tblFeatureListLocale]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				EXEC sp_executesql @SQL
			
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblFeatureListLocale_Insert procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblFeatureListLocale_Insert') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblFeatureListLocale_Insert
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Inserts a record into the tblFeatureListLocale table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblFeatureListLocale_Insert
(

	@Id int    OUTPUT,

	@LanguageId int   ,

	@FeatureId int   ,

	@Name nvarchar (256)  
)
AS


				
				INSERT INTO [dbo].[tblFeatureListLocale]
					(
					[LanguageId]
					,[FeatureId]
					,[Name]
					)
				VALUES
					(
					@LanguageId
					,@FeatureId
					,@Name
					)
				
				-- Get the identity value
				SET @Id = SCOPE_IDENTITY()
									
							
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblFeatureListLocale_Update procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblFeatureListLocale_Update') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblFeatureListLocale_Update
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Updates a record in the tblFeatureListLocale table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblFeatureListLocale_Update
(

	@Id int   ,

	@LanguageId int   ,

	@FeatureId int   ,

	@Name nvarchar (256)  
)
AS


				
				
				-- Modify the updatable columns
				UPDATE
					[dbo].[tblFeatureListLocale]
				SET
					[LanguageId] = @LanguageId
					,[FeatureId] = @FeatureId
					,[Name] = @Name
				WHERE
[Id] = @Id 
				
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblFeatureListLocale_Delete procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblFeatureListLocale_Delete') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblFeatureListLocale_Delete
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Deletes a record in the tblFeatureListLocale table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblFeatureListLocale_Delete
(

	@Id int   
)
AS


				DELETE FROM [dbo].[tblFeatureListLocale] WITH (ROWLOCK) 
				WHERE
					[Id] = @Id
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblFeatureListLocale_GetByFeatureId procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblFeatureListLocale_GetByFeatureId') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblFeatureListLocale_GetByFeatureId
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Select records from the tblFeatureListLocale table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblFeatureListLocale_GetByFeatureId
(

	@FeatureId int   
)
AS


				SET ANSI_NULLS OFF
				
				SELECT
					[Id],
					[LanguageId],
					[FeatureId],
					[Name]
				FROM
					[dbo].[tblFeatureListLocale]
				WHERE
					[FeatureId] = @FeatureId
				
				SELECT @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblFeatureListLocale_GetByLanguageId procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblFeatureListLocale_GetByLanguageId') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblFeatureListLocale_GetByLanguageId
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Select records from the tblFeatureListLocale table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblFeatureListLocale_GetByLanguageId
(

	@LanguageId int   
)
AS


				SET ANSI_NULLS OFF
				
				SELECT
					[Id],
					[LanguageId],
					[FeatureId],
					[Name]
				FROM
					[dbo].[tblFeatureListLocale]
				WHERE
					[LanguageId] = @LanguageId
				
				SELECT @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblFeatureListLocale_GetById procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblFeatureListLocale_GetById') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblFeatureListLocale_GetById
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Select records from the tblFeatureListLocale table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblFeatureListLocale_GetById
(

	@Id int   
)
AS


				SELECT
					[Id],
					[LanguageId],
					[FeatureId],
					[Name]
				FROM
					[dbo].[tblFeatureListLocale]
				WHERE
					[Id] = @Id
				SELECT @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblFeatureListLocale_Find procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblFeatureListLocale_Find') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblFeatureListLocale_Find
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Finds records in the tblFeatureListLocale table passing nullable parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblFeatureListLocale_Find
(

	@SearchUsingOR bit   = null ,

	@Id int   = null ,

	@LanguageId int   = null ,

	@FeatureId int   = null ,

	@Name nvarchar (256)  = null 
)
AS


				
  IF ISNULL(@SearchUsingOR, 0) <> 1
  BEGIN
    SELECT
	  [Id]
	, [LanguageId]
	, [FeatureId]
	, [Name]
    FROM
	[dbo].[tblFeatureListLocale]
    WHERE 
	 ([Id] = @Id OR @Id IS NULL)
	AND ([LanguageId] = @LanguageId OR @LanguageId IS NULL)
	AND ([FeatureId] = @FeatureId OR @FeatureId IS NULL)
	AND ([Name] = @Name OR @Name IS NULL)
						
  END
  ELSE
  BEGIN
    SELECT
	  [Id]
	, [LanguageId]
	, [FeatureId]
	, [Name]
    FROM
	[dbo].[tblFeatureListLocale]
    WHERE 
	 ([Id] = @Id AND @Id is not null)
	OR ([LanguageId] = @LanguageId AND @LanguageId is not null)
	OR ([FeatureId] = @FeatureId AND @FeatureId is not null)
	OR ([Name] = @Name AND @Name is not null)
	SELECT @@ROWCOUNT			
  END
				

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblAdvertisement_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblAdvertisement_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblAdvertisement_Get_List
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Gets all records from the tblAdvertisement table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblAdvertisement_Get_List

AS


				
				SELECT
					[Id],
					[ImagePath],
					[Website],
					[Name],
					[Description],
					[Position],
					[IsShow],
					[Type]
				FROM
					[dbo].[tblAdvertisement]
					
				SELECT @@ROWCOUNT
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblAdvertisement_GetPaged procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblAdvertisement_GetPaged') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblAdvertisement_GetPaged
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Gets records from the tblAdvertisement table passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblAdvertisement_GetPaged
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				
				BEGIN
				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				-- Create a temp table to store the select results
				CREATE TABLE #PageIndex
				(
				    [IndexId] int IDENTITY (1, 1) NOT NULL,
				    [Id] int 
				)
				
				-- Insert into the temp table
				DECLARE @SQL AS nvarchar(4000)
				SET @SQL = 'INSERT INTO #PageIndex ([Id])'
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + CONVERT(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' [Id]'
				SET @SQL = @SQL + ' FROM [dbo].[tblAdvertisement]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				IF LEN(@OrderBy) > 0
				BEGIN
					SET @SQL = @SQL + ' ORDER BY ' + @OrderBy
				END
				
				-- Populate the temp table
				EXEC sp_executesql @SQL

				-- Return paged results
				SELECT O.[Id], O.[ImagePath], O.[Website], O.[Name], O.[Description], O.[Position], O.[IsShow], O.[Type]
				FROM
				    [dbo].[tblAdvertisement] O,
				    #PageIndex PageIndex
				WHERE
				    PageIndex.IndexId > @PageLowerBound
					AND O.[Id] = PageIndex.[Id]
				ORDER BY
				    PageIndex.IndexId
				
				-- get row count
				SET @SQL = 'SELECT COUNT(*) AS TotalRowCount'
				SET @SQL = @SQL + ' FROM [dbo].[tblAdvertisement]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				EXEC sp_executesql @SQL
			
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblAdvertisement_Insert procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblAdvertisement_Insert') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblAdvertisement_Insert
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Inserts a record into the tblAdvertisement table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblAdvertisement_Insert
(

	@Id int    OUTPUT,

	@ImagePath nvarchar (256)  ,

	@Website nvarchar (128)  ,

	@Name nvarchar (128)  ,

	@Description nvarchar (1024)  ,

	@Position int   ,

	@IsShow bit   ,

	@Type char (1)  
)
AS


				
				INSERT INTO [dbo].[tblAdvertisement]
					(
					[ImagePath]
					,[Website]
					,[Name]
					,[Description]
					,[Position]
					,[IsShow]
					,[Type]
					)
				VALUES
					(
					@ImagePath
					,@Website
					,@Name
					,@Description
					,@Position
					,@IsShow
					,@Type
					)
				
				-- Get the identity value
				SET @Id = SCOPE_IDENTITY()
									
							
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblAdvertisement_Update procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblAdvertisement_Update') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblAdvertisement_Update
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Updates a record in the tblAdvertisement table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblAdvertisement_Update
(

	@Id int   ,

	@ImagePath nvarchar (256)  ,

	@Website nvarchar (128)  ,

	@Name nvarchar (128)  ,

	@Description nvarchar (1024)  ,

	@Position int   ,

	@IsShow bit   ,

	@Type char (1)  
)
AS


				
				
				-- Modify the updatable columns
				UPDATE
					[dbo].[tblAdvertisement]
				SET
					[ImagePath] = @ImagePath
					,[Website] = @Website
					,[Name] = @Name
					,[Description] = @Description
					,[Position] = @Position
					,[IsShow] = @IsShow
					,[Type] = @Type
				WHERE
[Id] = @Id 
				
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblAdvertisement_Delete procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblAdvertisement_Delete') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblAdvertisement_Delete
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Deletes a record in the tblAdvertisement table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblAdvertisement_Delete
(

	@Id int   
)
AS


				DELETE FROM [dbo].[tblAdvertisement] WITH (ROWLOCK) 
				WHERE
					[Id] = @Id
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblAdvertisement_GetById procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblAdvertisement_GetById') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblAdvertisement_GetById
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Select records from the tblAdvertisement table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblAdvertisement_GetById
(

	@Id int   
)
AS


				SELECT
					[Id],
					[ImagePath],
					[Website],
					[Name],
					[Description],
					[Position],
					[IsShow],
					[Type]
				FROM
					[dbo].[tblAdvertisement]
				WHERE
					[Id] = @Id
				SELECT @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblAdvertisement_Find procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblAdvertisement_Find') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblAdvertisement_Find
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Finds records in the tblAdvertisement table passing nullable parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblAdvertisement_Find
(

	@SearchUsingOR bit   = null ,

	@Id int   = null ,

	@ImagePath nvarchar (256)  = null ,

	@Website nvarchar (128)  = null ,

	@Name nvarchar (128)  = null ,

	@Description nvarchar (1024)  = null ,

	@Position int   = null ,

	@IsShow bit   = null ,

	@Type char (1)  = null 
)
AS


				
  IF ISNULL(@SearchUsingOR, 0) <> 1
  BEGIN
    SELECT
	  [Id]
	, [ImagePath]
	, [Website]
	, [Name]
	, [Description]
	, [Position]
	, [IsShow]
	, [Type]
    FROM
	[dbo].[tblAdvertisement]
    WHERE 
	 ([Id] = @Id OR @Id IS NULL)
	AND ([ImagePath] = @ImagePath OR @ImagePath IS NULL)
	AND ([Website] = @Website OR @Website IS NULL)
	AND ([Name] = @Name OR @Name IS NULL)
	AND ([Description] = @Description OR @Description IS NULL)
	AND ([Position] = @Position OR @Position IS NULL)
	AND ([IsShow] = @IsShow OR @IsShow IS NULL)
	AND ([Type] = @Type OR @Type IS NULL)
						
  END
  ELSE
  BEGIN
    SELECT
	  [Id]
	, [ImagePath]
	, [Website]
	, [Name]
	, [Description]
	, [Position]
	, [IsShow]
	, [Type]
    FROM
	[dbo].[tblAdvertisement]
    WHERE 
	 ([Id] = @Id AND @Id is not null)
	OR ([ImagePath] = @ImagePath AND @ImagePath is not null)
	OR ([Website] = @Website AND @Website is not null)
	OR ([Name] = @Name AND @Name is not null)
	OR ([Description] = @Description AND @Description is not null)
	OR ([Position] = @Position AND @Position is not null)
	OR ([IsShow] = @IsShow AND @IsShow is not null)
	OR ([Type] = @Type AND @Type is not null)
	SELECT @@ROWCOUNT			
  END
				

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblFunction_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblFunction_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblFunction_Get_List
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Gets all records from the tblFunction table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblFunction_Get_List

AS


				
				SELECT
					[Id],
					[Name],
					[Description],
					[IsVisible]
				FROM
					[dbo].[tblFunction]
					
				SELECT @@ROWCOUNT
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblFunction_GetPaged procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblFunction_GetPaged') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblFunction_GetPaged
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Gets records from the tblFunction table passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblFunction_GetPaged
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				
				BEGIN
				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				-- Create a temp table to store the select results
				CREATE TABLE #PageIndex
				(
				    [IndexId] int IDENTITY (1, 1) NOT NULL,
				    [Id] int 
				)
				
				-- Insert into the temp table
				DECLARE @SQL AS nvarchar(4000)
				SET @SQL = 'INSERT INTO #PageIndex ([Id])'
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + CONVERT(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' [Id]'
				SET @SQL = @SQL + ' FROM [dbo].[tblFunction]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				IF LEN(@OrderBy) > 0
				BEGIN
					SET @SQL = @SQL + ' ORDER BY ' + @OrderBy
				END
				
				-- Populate the temp table
				EXEC sp_executesql @SQL

				-- Return paged results
				SELECT O.[Id], O.[Name], O.[Description], O.[IsVisible]
				FROM
				    [dbo].[tblFunction] O,
				    #PageIndex PageIndex
				WHERE
				    PageIndex.IndexId > @PageLowerBound
					AND O.[Id] = PageIndex.[Id]
				ORDER BY
				    PageIndex.IndexId
				
				-- get row count
				SET @SQL = 'SELECT COUNT(*) AS TotalRowCount'
				SET @SQL = @SQL + ' FROM [dbo].[tblFunction]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				EXEC sp_executesql @SQL
			
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblFunction_Insert procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblFunction_Insert') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblFunction_Insert
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Inserts a record into the tblFunction table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblFunction_Insert
(

	@Id int    OUTPUT,

	@Name varchar (50)  ,

	@Description nvarchar (256)  ,

	@IsVisible bit   
)
AS


				
				INSERT INTO [dbo].[tblFunction]
					(
					[Name]
					,[Description]
					,[IsVisible]
					)
				VALUES
					(
					@Name
					,@Description
					,@IsVisible
					)
				
				-- Get the identity value
				SET @Id = SCOPE_IDENTITY()
									
							
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblFunction_Update procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblFunction_Update') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblFunction_Update
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Updates a record in the tblFunction table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblFunction_Update
(

	@Id int   ,

	@Name varchar (50)  ,

	@Description nvarchar (256)  ,

	@IsVisible bit   
)
AS


				
				
				-- Modify the updatable columns
				UPDATE
					[dbo].[tblFunction]
				SET
					[Name] = @Name
					,[Description] = @Description
					,[IsVisible] = @IsVisible
				WHERE
[Id] = @Id 
				
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblFunction_Delete procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblFunction_Delete') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblFunction_Delete
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Deletes a record in the tblFunction table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblFunction_Delete
(

	@Id int   
)
AS


				DELETE FROM [dbo].[tblFunction] WITH (ROWLOCK) 
				WHERE
					[Id] = @Id
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblFunction_GetById procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblFunction_GetById') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblFunction_GetById
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Select records from the tblFunction table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblFunction_GetById
(

	@Id int   
)
AS


				SELECT
					[Id],
					[Name],
					[Description],
					[IsVisible]
				FROM
					[dbo].[tblFunction]
				WHERE
					[Id] = @Id
				SELECT @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblFunction_GetByName procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblFunction_GetByName') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblFunction_GetByName
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Select records from the tblFunction table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblFunction_GetByName
(

	@Name varchar (50)  
)
AS


				SELECT
					[Id],
					[Name],
					[Description],
					[IsVisible]
				FROM
					[dbo].[tblFunction]
				WHERE
					[Name] = @Name
				SELECT @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblFunction_Find procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblFunction_Find') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblFunction_Find
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Finds records in the tblFunction table passing nullable parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblFunction_Find
(

	@SearchUsingOR bit   = null ,

	@Id int   = null ,

	@Name varchar (50)  = null ,

	@Description nvarchar (256)  = null ,

	@IsVisible bit   = null 
)
AS


				
  IF ISNULL(@SearchUsingOR, 0) <> 1
  BEGIN
    SELECT
	  [Id]
	, [Name]
	, [Description]
	, [IsVisible]
    FROM
	[dbo].[tblFunction]
    WHERE 
	 ([Id] = @Id OR @Id IS NULL)
	AND ([Name] = @Name OR @Name IS NULL)
	AND ([Description] = @Description OR @Description IS NULL)
	AND ([IsVisible] = @IsVisible OR @IsVisible IS NULL)
						
  END
  ELSE
  BEGIN
    SELECT
	  [Id]
	, [Name]
	, [Description]
	, [IsVisible]
    FROM
	[dbo].[tblFunction]
    WHERE 
	 ([Id] = @Id AND @Id is not null)
	OR ([Name] = @Name AND @Name is not null)
	OR ([Description] = @Description AND @Description is not null)
	OR ([IsVisible] = @IsVisible AND @IsVisible is not null)
	SELECT @@ROWCOUNT			
  END
				

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblUserGroup_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblUserGroup_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblUserGroup_Get_List
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Gets all records from the tblUserGroup table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblUserGroup_Get_List

AS


				
				SELECT
					[Id],
					[GroupId],
					[Username]
				FROM
					[dbo].[tblUserGroup]
					
				SELECT @@ROWCOUNT
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblUserGroup_GetPaged procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblUserGroup_GetPaged') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblUserGroup_GetPaged
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Gets records from the tblUserGroup table passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblUserGroup_GetPaged
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				
				BEGIN
				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				-- Create a temp table to store the select results
				CREATE TABLE #PageIndex
				(
				    [IndexId] int IDENTITY (1, 1) NOT NULL,
				    [Id] int 
				)
				
				-- Insert into the temp table
				DECLARE @SQL AS nvarchar(4000)
				SET @SQL = 'INSERT INTO #PageIndex ([Id])'
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + CONVERT(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' [Id]'
				SET @SQL = @SQL + ' FROM [dbo].[tblUserGroup]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				IF LEN(@OrderBy) > 0
				BEGIN
					SET @SQL = @SQL + ' ORDER BY ' + @OrderBy
				END
				
				-- Populate the temp table
				EXEC sp_executesql @SQL

				-- Return paged results
				SELECT O.[Id], O.[GroupId], O.[Username]
				FROM
				    [dbo].[tblUserGroup] O,
				    #PageIndex PageIndex
				WHERE
				    PageIndex.IndexId > @PageLowerBound
					AND O.[Id] = PageIndex.[Id]
				ORDER BY
				    PageIndex.IndexId
				
				-- get row count
				SET @SQL = 'SELECT COUNT(*) AS TotalRowCount'
				SET @SQL = @SQL + ' FROM [dbo].[tblUserGroup]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				EXEC sp_executesql @SQL
			
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblUserGroup_Insert procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblUserGroup_Insert') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblUserGroup_Insert
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Inserts a record into the tblUserGroup table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblUserGroup_Insert
(

	@Id int    OUTPUT,

	@GroupId int   ,

	@Username varchar (50)  
)
AS


				
				INSERT INTO [dbo].[tblUserGroup]
					(
					[GroupId]
					,[Username]
					)
				VALUES
					(
					@GroupId
					,@Username
					)
				
				-- Get the identity value
				SET @Id = SCOPE_IDENTITY()
									
							
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblUserGroup_Update procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblUserGroup_Update') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblUserGroup_Update
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Updates a record in the tblUserGroup table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblUserGroup_Update
(

	@Id int   ,

	@GroupId int   ,

	@Username varchar (50)  
)
AS


				
				
				-- Modify the updatable columns
				UPDATE
					[dbo].[tblUserGroup]
				SET
					[GroupId] = @GroupId
					,[Username] = @Username
				WHERE
[Id] = @Id 
				
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblUserGroup_Delete procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblUserGroup_Delete') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblUserGroup_Delete
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Deletes a record in the tblUserGroup table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblUserGroup_Delete
(

	@Id int   
)
AS


				DELETE FROM [dbo].[tblUserGroup] WITH (ROWLOCK) 
				WHERE
					[Id] = @Id
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblUserGroup_GetByGroupId procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblUserGroup_GetByGroupId') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblUserGroup_GetByGroupId
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Select records from the tblUserGroup table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblUserGroup_GetByGroupId
(

	@GroupId int   
)
AS


				SET ANSI_NULLS OFF
				
				SELECT
					[Id],
					[GroupId],
					[Username]
				FROM
					[dbo].[tblUserGroup]
				WHERE
					[GroupId] = @GroupId
				
				SELECT @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblUserGroup_GetByUsername procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblUserGroup_GetByUsername') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblUserGroup_GetByUsername
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Select records from the tblUserGroup table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblUserGroup_GetByUsername
(

	@Username varchar (50)  
)
AS


				SET ANSI_NULLS OFF
				
				SELECT
					[Id],
					[GroupId],
					[Username]
				FROM
					[dbo].[tblUserGroup]
				WHERE
					[Username] = @Username
				
				SELECT @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblUserGroup_GetById procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblUserGroup_GetById') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblUserGroup_GetById
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Select records from the tblUserGroup table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblUserGroup_GetById
(

	@Id int   
)
AS


				SELECT
					[Id],
					[GroupId],
					[Username]
				FROM
					[dbo].[tblUserGroup]
				WHERE
					[Id] = @Id
				SELECT @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblUserGroup_Find procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblUserGroup_Find') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblUserGroup_Find
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Finds records in the tblUserGroup table passing nullable parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblUserGroup_Find
(

	@SearchUsingOR bit   = null ,

	@Id int   = null ,

	@GroupId int   = null ,

	@Username varchar (50)  = null 
)
AS


				
  IF ISNULL(@SearchUsingOR, 0) <> 1
  BEGIN
    SELECT
	  [Id]
	, [GroupId]
	, [Username]
    FROM
	[dbo].[tblUserGroup]
    WHERE 
	 ([Id] = @Id OR @Id IS NULL)
	AND ([GroupId] = @GroupId OR @GroupId IS NULL)
	AND ([Username] = @Username OR @Username IS NULL)
						
  END
  ELSE
  BEGIN
    SELECT
	  [Id]
	, [GroupId]
	, [Username]
    FROM
	[dbo].[tblUserGroup]
    WHERE 
	 ([Id] = @Id AND @Id is not null)
	OR ([GroupId] = @GroupId AND @GroupId is not null)
	OR ([Username] = @Username AND @Username is not null)
	SELECT @@ROWCOUNT			
  END
				

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblMainMenu_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblMainMenu_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblMainMenu_Get_List
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Gets all records from the tblMainMenu table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblMainMenu_Get_List

AS


				
				SELECT
					[Id],
					[Code],
					[Name],
					[Link],
					[Pages],
					[Type],
					[ParentId],
					[FunctionId],
					[Order],
					[SubMenuSource],
					[LayoutPosition]
				FROM
					[dbo].[tblMainMenu]
					
				SELECT @@ROWCOUNT
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblMainMenu_GetPaged procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblMainMenu_GetPaged') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblMainMenu_GetPaged
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Gets records from the tblMainMenu table passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblMainMenu_GetPaged
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				
				BEGIN
				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				-- Create a temp table to store the select results
				CREATE TABLE #PageIndex
				(
				    [IndexId] int IDENTITY (1, 1) NOT NULL,
				    [Id] int 
				)
				
				-- Insert into the temp table
				DECLARE @SQL AS nvarchar(4000)
				SET @SQL = 'INSERT INTO #PageIndex ([Id])'
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + CONVERT(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' [Id]'
				SET @SQL = @SQL + ' FROM [dbo].[tblMainMenu]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				IF LEN(@OrderBy) > 0
				BEGIN
					SET @SQL = @SQL + ' ORDER BY ' + @OrderBy
				END
				
				-- Populate the temp table
				EXEC sp_executesql @SQL

				-- Return paged results
				SELECT O.[Id], O.[Code], O.[Name], O.[Link], O.[Pages], O.[Type], O.[ParentId], O.[FunctionId], O.[Order], O.[SubMenuSource], O.[LayoutPosition]
				FROM
				    [dbo].[tblMainMenu] O,
				    #PageIndex PageIndex
				WHERE
				    PageIndex.IndexId > @PageLowerBound
					AND O.[Id] = PageIndex.[Id]
				ORDER BY
				    PageIndex.IndexId
				
				-- get row count
				SET @SQL = 'SELECT COUNT(*) AS TotalRowCount'
				SET @SQL = @SQL + ' FROM [dbo].[tblMainMenu]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				EXEC sp_executesql @SQL
			
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblMainMenu_Insert procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblMainMenu_Insert') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblMainMenu_Insert
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Inserts a record into the tblMainMenu table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblMainMenu_Insert
(

	@Id int    OUTPUT,

	@Code varchar (50)  ,

	@Name nvarchar (128)  ,

	@Link nvarchar (512)  ,

	@Pages nvarchar (4000)  ,

	@Type char (1)  ,

	@ParentId int   ,

	@FunctionId int   ,

	@Order int   ,

	@SubMenuSource char (1)  ,

	@LayoutPosition int   
)
AS


				
				INSERT INTO [dbo].[tblMainMenu]
					(
					[Code]
					,[Name]
					,[Link]
					,[Pages]
					,[Type]
					,[ParentId]
					,[FunctionId]
					,[Order]
					,[SubMenuSource]
					,[LayoutPosition]
					)
				VALUES
					(
					@Code
					,@Name
					,@Link
					,@Pages
					,@Type
					,@ParentId
					,@FunctionId
					,@Order
					,@SubMenuSource
					,@LayoutPosition
					)
				
				-- Get the identity value
				SET @Id = SCOPE_IDENTITY()
									
							
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblMainMenu_Update procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblMainMenu_Update') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblMainMenu_Update
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Updates a record in the tblMainMenu table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblMainMenu_Update
(

	@Id int   ,

	@Code varchar (50)  ,

	@Name nvarchar (128)  ,

	@Link nvarchar (512)  ,

	@Pages nvarchar (4000)  ,

	@Type char (1)  ,

	@ParentId int   ,

	@FunctionId int   ,

	@Order int   ,

	@SubMenuSource char (1)  ,

	@LayoutPosition int   
)
AS


				
				
				-- Modify the updatable columns
				UPDATE
					[dbo].[tblMainMenu]
				SET
					[Code] = @Code
					,[Name] = @Name
					,[Link] = @Link
					,[Pages] = @Pages
					,[Type] = @Type
					,[ParentId] = @ParentId
					,[FunctionId] = @FunctionId
					,[Order] = @Order
					,[SubMenuSource] = @SubMenuSource
					,[LayoutPosition] = @LayoutPosition
				WHERE
[Id] = @Id 
				
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblMainMenu_Delete procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblMainMenu_Delete') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblMainMenu_Delete
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Deletes a record in the tblMainMenu table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblMainMenu_Delete
(

	@Id int   
)
AS


				DELETE FROM [dbo].[tblMainMenu] WITH (ROWLOCK) 
				WHERE
					[Id] = @Id
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblMainMenu_GetById procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblMainMenu_GetById') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblMainMenu_GetById
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Select records from the tblMainMenu table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblMainMenu_GetById
(

	@Id int   
)
AS


				SELECT
					[Id],
					[Code],
					[Name],
					[Link],
					[Pages],
					[Type],
					[ParentId],
					[FunctionId],
					[Order],
					[SubMenuSource],
					[LayoutPosition]
				FROM
					[dbo].[tblMainMenu]
				WHERE
					[Id] = @Id
				SELECT @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblMainMenu_GetByCode procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblMainMenu_GetByCode') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblMainMenu_GetByCode
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Select records from the tblMainMenu table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblMainMenu_GetByCode
(

	@Code varchar (50)  
)
AS


				SELECT
					[Id],
					[Code],
					[Name],
					[Link],
					[Pages],
					[Type],
					[ParentId],
					[FunctionId],
					[Order],
					[SubMenuSource],
					[LayoutPosition]
				FROM
					[dbo].[tblMainMenu]
				WHERE
					[Code] = @Code
				SELECT @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblMainMenu_Find procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblMainMenu_Find') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblMainMenu_Find
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Finds records in the tblMainMenu table passing nullable parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblMainMenu_Find
(

	@SearchUsingOR bit   = null ,

	@Id int   = null ,

	@Code varchar (50)  = null ,

	@Name nvarchar (128)  = null ,

	@Link nvarchar (512)  = null ,

	@Pages nvarchar (4000)  = null ,

	@Type char (1)  = null ,

	@ParentId int   = null ,

	@FunctionId int   = null ,

	@Order int   = null ,

	@SubMenuSource char (1)  = null ,

	@LayoutPosition int   = null 
)
AS


				
  IF ISNULL(@SearchUsingOR, 0) <> 1
  BEGIN
    SELECT
	  [Id]
	, [Code]
	, [Name]
	, [Link]
	, [Pages]
	, [Type]
	, [ParentId]
	, [FunctionId]
	, [Order]
	, [SubMenuSource]
	, [LayoutPosition]
    FROM
	[dbo].[tblMainMenu]
    WHERE 
	 ([Id] = @Id OR @Id IS NULL)
	AND ([Code] = @Code OR @Code IS NULL)
	AND ([Name] = @Name OR @Name IS NULL)
	AND ([Link] = @Link OR @Link IS NULL)
	AND ([Pages] = @Pages OR @Pages IS NULL)
	AND ([Type] = @Type OR @Type IS NULL)
	AND ([ParentId] = @ParentId OR @ParentId IS NULL)
	AND ([FunctionId] = @FunctionId OR @FunctionId IS NULL)
	AND ([Order] = @Order OR @Order IS NULL)
	AND ([SubMenuSource] = @SubMenuSource OR @SubMenuSource IS NULL)
	AND ([LayoutPosition] = @LayoutPosition OR @LayoutPosition IS NULL)
						
  END
  ELSE
  BEGIN
    SELECT
	  [Id]
	, [Code]
	, [Name]
	, [Link]
	, [Pages]
	, [Type]
	, [ParentId]
	, [FunctionId]
	, [Order]
	, [SubMenuSource]
	, [LayoutPosition]
    FROM
	[dbo].[tblMainMenu]
    WHERE 
	 ([Id] = @Id AND @Id is not null)
	OR ([Code] = @Code AND @Code is not null)
	OR ([Name] = @Name AND @Name is not null)
	OR ([Link] = @Link AND @Link is not null)
	OR ([Pages] = @Pages AND @Pages is not null)
	OR ([Type] = @Type AND @Type is not null)
	OR ([ParentId] = @ParentId AND @ParentId is not null)
	OR ([FunctionId] = @FunctionId AND @FunctionId is not null)
	OR ([Order] = @Order AND @Order is not null)
	OR ([SubMenuSource] = @SubMenuSource AND @SubMenuSource is not null)
	OR ([LayoutPosition] = @LayoutPosition AND @LayoutPosition is not null)
	SELECT @@ROWCOUNT			
  END
				

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblLanguage_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblLanguage_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblLanguage_Get_List
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Gets all records from the tblLanguage table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblLanguage_Get_List

AS


				
				SELECT
					[Id],
					[Name],
					[Culture]
				FROM
					[dbo].[tblLanguage]
					
				SELECT @@ROWCOUNT
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblLanguage_GetPaged procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblLanguage_GetPaged') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblLanguage_GetPaged
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Gets records from the tblLanguage table passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblLanguage_GetPaged
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				
				BEGIN
				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				-- Create a temp table to store the select results
				CREATE TABLE #PageIndex
				(
				    [IndexId] int IDENTITY (1, 1) NOT NULL,
				    [Id] int 
				)
				
				-- Insert into the temp table
				DECLARE @SQL AS nvarchar(4000)
				SET @SQL = 'INSERT INTO #PageIndex ([Id])'
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + CONVERT(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' [Id]'
				SET @SQL = @SQL + ' FROM [dbo].[tblLanguage]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				IF LEN(@OrderBy) > 0
				BEGIN
					SET @SQL = @SQL + ' ORDER BY ' + @OrderBy
				END
				
				-- Populate the temp table
				EXEC sp_executesql @SQL

				-- Return paged results
				SELECT O.[Id], O.[Name], O.[Culture]
				FROM
				    [dbo].[tblLanguage] O,
				    #PageIndex PageIndex
				WHERE
				    PageIndex.IndexId > @PageLowerBound
					AND O.[Id] = PageIndex.[Id]
				ORDER BY
				    PageIndex.IndexId
				
				-- get row count
				SET @SQL = 'SELECT COUNT(*) AS TotalRowCount'
				SET @SQL = @SQL + ' FROM [dbo].[tblLanguage]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				EXEC sp_executesql @SQL
			
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblLanguage_Insert procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblLanguage_Insert') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblLanguage_Insert
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Inserts a record into the tblLanguage table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblLanguage_Insert
(

	@Id int    OUTPUT,

	@Name nvarchar (50)  ,

	@Culture varchar (10)  
)
AS


				
				INSERT INTO [dbo].[tblLanguage]
					(
					[Name]
					,[Culture]
					)
				VALUES
					(
					@Name
					,@Culture
					)
				
				-- Get the identity value
				SET @Id = SCOPE_IDENTITY()
									
							
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblLanguage_Update procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblLanguage_Update') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblLanguage_Update
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Updates a record in the tblLanguage table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblLanguage_Update
(

	@Id int   ,

	@Name nvarchar (50)  ,

	@Culture varchar (10)  
)
AS


				
				
				-- Modify the updatable columns
				UPDATE
					[dbo].[tblLanguage]
				SET
					[Name] = @Name
					,[Culture] = @Culture
				WHERE
[Id] = @Id 
				
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblLanguage_Delete procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblLanguage_Delete') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblLanguage_Delete
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Deletes a record in the tblLanguage table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblLanguage_Delete
(

	@Id int   
)
AS


				DELETE FROM [dbo].[tblLanguage] WITH (ROWLOCK) 
				WHERE
					[Id] = @Id
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblLanguage_GetById procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblLanguage_GetById') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblLanguage_GetById
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Select records from the tblLanguage table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblLanguage_GetById
(

	@Id int   
)
AS


				SELECT
					[Id],
					[Name],
					[Culture]
				FROM
					[dbo].[tblLanguage]
				WHERE
					[Id] = @Id
				SELECT @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblLanguage_GetByName procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblLanguage_GetByName') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblLanguage_GetByName
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Select records from the tblLanguage table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblLanguage_GetByName
(

	@Name nvarchar (50)  
)
AS


				SELECT
					[Id],
					[Name],
					[Culture]
				FROM
					[dbo].[tblLanguage]
				WHERE
					[Name] = @Name
				SELECT @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblLanguage_Find procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblLanguage_Find') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblLanguage_Find
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Finds records in the tblLanguage table passing nullable parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblLanguage_Find
(

	@SearchUsingOR bit   = null ,

	@Id int   = null ,

	@Name nvarchar (50)  = null ,

	@Culture varchar (10)  = null 
)
AS


				
  IF ISNULL(@SearchUsingOR, 0) <> 1
  BEGIN
    SELECT
	  [Id]
	, [Name]
	, [Culture]
    FROM
	[dbo].[tblLanguage]
    WHERE 
	 ([Id] = @Id OR @Id IS NULL)
	AND ([Name] = @Name OR @Name IS NULL)
	AND ([Culture] = @Culture OR @Culture IS NULL)
						
  END
  ELSE
  BEGIN
    SELECT
	  [Id]
	, [Name]
	, [Culture]
    FROM
	[dbo].[tblLanguage]
    WHERE 
	 ([Id] = @Id AND @Id is not null)
	OR ([Name] = @Name AND @Name is not null)
	OR ([Culture] = @Culture AND @Culture is not null)
	SELECT @@ROWCOUNT			
  END
				

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblMainMenuLocale_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblMainMenuLocale_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblMainMenuLocale_Get_List
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Gets all records from the tblMainMenuLocale table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblMainMenuLocale_Get_List

AS


				
				SELECT
					[Id],
					[MainMenuId],
					[LanguageId],
					[Name]
				FROM
					[dbo].[tblMainMenuLocale]
					
				SELECT @@ROWCOUNT
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblMainMenuLocale_GetPaged procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblMainMenuLocale_GetPaged') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblMainMenuLocale_GetPaged
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Gets records from the tblMainMenuLocale table passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblMainMenuLocale_GetPaged
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				
				BEGIN
				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				-- Create a temp table to store the select results
				CREATE TABLE #PageIndex
				(
				    [IndexId] int IDENTITY (1, 1) NOT NULL,
				    [Id] int 
				)
				
				-- Insert into the temp table
				DECLARE @SQL AS nvarchar(4000)
				SET @SQL = 'INSERT INTO #PageIndex ([Id])'
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + CONVERT(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' [Id]'
				SET @SQL = @SQL + ' FROM [dbo].[tblMainMenuLocale]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				IF LEN(@OrderBy) > 0
				BEGIN
					SET @SQL = @SQL + ' ORDER BY ' + @OrderBy
				END
				
				-- Populate the temp table
				EXEC sp_executesql @SQL

				-- Return paged results
				SELECT O.[Id], O.[MainMenuId], O.[LanguageId], O.[Name]
				FROM
				    [dbo].[tblMainMenuLocale] O,
				    #PageIndex PageIndex
				WHERE
				    PageIndex.IndexId > @PageLowerBound
					AND O.[Id] = PageIndex.[Id]
				ORDER BY
				    PageIndex.IndexId
				
				-- get row count
				SET @SQL = 'SELECT COUNT(*) AS TotalRowCount'
				SET @SQL = @SQL + ' FROM [dbo].[tblMainMenuLocale]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				EXEC sp_executesql @SQL
			
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblMainMenuLocale_Insert procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblMainMenuLocale_Insert') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblMainMenuLocale_Insert
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Inserts a record into the tblMainMenuLocale table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblMainMenuLocale_Insert
(

	@Id int    OUTPUT,

	@MainMenuId int   ,

	@LanguageId int   ,

	@Name nvarchar (128)  
)
AS


				
				INSERT INTO [dbo].[tblMainMenuLocale]
					(
					[MainMenuId]
					,[LanguageId]
					,[Name]
					)
				VALUES
					(
					@MainMenuId
					,@LanguageId
					,@Name
					)
				
				-- Get the identity value
				SET @Id = SCOPE_IDENTITY()
									
							
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblMainMenuLocale_Update procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblMainMenuLocale_Update') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblMainMenuLocale_Update
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Updates a record in the tblMainMenuLocale table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblMainMenuLocale_Update
(

	@Id int   ,

	@MainMenuId int   ,

	@LanguageId int   ,

	@Name nvarchar (128)  
)
AS


				
				
				-- Modify the updatable columns
				UPDATE
					[dbo].[tblMainMenuLocale]
				SET
					[MainMenuId] = @MainMenuId
					,[LanguageId] = @LanguageId
					,[Name] = @Name
				WHERE
[Id] = @Id 
				
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblMainMenuLocale_Delete procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblMainMenuLocale_Delete') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblMainMenuLocale_Delete
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Deletes a record in the tblMainMenuLocale table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblMainMenuLocale_Delete
(

	@Id int   
)
AS


				DELETE FROM [dbo].[tblMainMenuLocale] WITH (ROWLOCK) 
				WHERE
					[Id] = @Id
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblMainMenuLocale_GetByLanguageId procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblMainMenuLocale_GetByLanguageId') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblMainMenuLocale_GetByLanguageId
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Select records from the tblMainMenuLocale table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblMainMenuLocale_GetByLanguageId
(

	@LanguageId int   
)
AS


				SET ANSI_NULLS OFF
				
				SELECT
					[Id],
					[MainMenuId],
					[LanguageId],
					[Name]
				FROM
					[dbo].[tblMainMenuLocale]
				WHERE
					[LanguageId] = @LanguageId
				
				SELECT @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblMainMenuLocale_GetByMainMenuId procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblMainMenuLocale_GetByMainMenuId') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblMainMenuLocale_GetByMainMenuId
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Select records from the tblMainMenuLocale table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblMainMenuLocale_GetByMainMenuId
(

	@MainMenuId int   
)
AS


				SET ANSI_NULLS OFF
				
				SELECT
					[Id],
					[MainMenuId],
					[LanguageId],
					[Name]
				FROM
					[dbo].[tblMainMenuLocale]
				WHERE
					[MainMenuId] = @MainMenuId
				
				SELECT @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblMainMenuLocale_GetById procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblMainMenuLocale_GetById') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblMainMenuLocale_GetById
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Select records from the tblMainMenuLocale table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblMainMenuLocale_GetById
(

	@Id int   
)
AS


				SELECT
					[Id],
					[MainMenuId],
					[LanguageId],
					[Name]
				FROM
					[dbo].[tblMainMenuLocale]
				WHERE
					[Id] = @Id
				SELECT @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblMainMenuLocale_Find procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblMainMenuLocale_Find') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblMainMenuLocale_Find
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Finds records in the tblMainMenuLocale table passing nullable parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblMainMenuLocale_Find
(

	@SearchUsingOR bit   = null ,

	@Id int   = null ,

	@MainMenuId int   = null ,

	@LanguageId int   = null ,

	@Name nvarchar (128)  = null 
)
AS


				
  IF ISNULL(@SearchUsingOR, 0) <> 1
  BEGIN
    SELECT
	  [Id]
	, [MainMenuId]
	, [LanguageId]
	, [Name]
    FROM
	[dbo].[tblMainMenuLocale]
    WHERE 
	 ([Id] = @Id OR @Id IS NULL)
	AND ([MainMenuId] = @MainMenuId OR @MainMenuId IS NULL)
	AND ([LanguageId] = @LanguageId OR @LanguageId IS NULL)
	AND ([Name] = @Name OR @Name IS NULL)
						
  END
  ELSE
  BEGIN
    SELECT
	  [Id]
	, [MainMenuId]
	, [LanguageId]
	, [Name]
    FROM
	[dbo].[tblMainMenuLocale]
    WHERE 
	 ([Id] = @Id AND @Id is not null)
	OR ([MainMenuId] = @MainMenuId AND @MainMenuId is not null)
	OR ([LanguageId] = @LanguageId AND @LanguageId is not null)
	OR ([Name] = @Name AND @Name is not null)
	SELECT @@ROWCOUNT			
  END
				

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblHtmlContent_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblHtmlContent_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblHtmlContent_Get_List
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Gets all records from the tblHtmlContent table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblHtmlContent_Get_List

AS


				
				SELECT
					[Id],
					[Name],
					[Summary],
					[Content],
					[LanguageId],
					[TypeId],
					[Status],
					[CreatedDate],
					[CreatedBy],
					[ModifiedDate],
					[ModifiedBy],
					[ApprovedDate],
					[ApprovedBy],
					[Tags]
				FROM
					[dbo].[tblHtmlContent]
					
				SELECT @@ROWCOUNT
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblHtmlContent_GetPaged procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblHtmlContent_GetPaged') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblHtmlContent_GetPaged
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Gets records from the tblHtmlContent table passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblHtmlContent_GetPaged
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				
				BEGIN
				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				-- Create a temp table to store the select results
				CREATE TABLE #PageIndex
				(
				    [IndexId] int IDENTITY (1, 1) NOT NULL,
				    [Id] int 
				)
				
				-- Insert into the temp table
				DECLARE @SQL AS nvarchar(4000)
				SET @SQL = 'INSERT INTO #PageIndex ([Id])'
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + CONVERT(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' [Id]'
				SET @SQL = @SQL + ' FROM [dbo].[tblHtmlContent]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				IF LEN(@OrderBy) > 0
				BEGIN
					SET @SQL = @SQL + ' ORDER BY ' + @OrderBy
				END
				
				-- Populate the temp table
				EXEC sp_executesql @SQL

				-- Return paged results
				SELECT O.[Id], O.[Name], O.[Summary], O.[Content], O.[LanguageId], O.[TypeId], O.[Status], O.[CreatedDate], O.[CreatedBy], O.[ModifiedDate], O.[ModifiedBy], O.[ApprovedDate], O.[ApprovedBy], O.[Tags]
				FROM
				    [dbo].[tblHtmlContent] O,
				    #PageIndex PageIndex
				WHERE
				    PageIndex.IndexId > @PageLowerBound
					AND O.[Id] = PageIndex.[Id]
				ORDER BY
				    PageIndex.IndexId
				
				-- get row count
				SET @SQL = 'SELECT COUNT(*) AS TotalRowCount'
				SET @SQL = @SQL + ' FROM [dbo].[tblHtmlContent]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				EXEC sp_executesql @SQL
			
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblHtmlContent_Insert procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblHtmlContent_Insert') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblHtmlContent_Insert
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Inserts a record into the tblHtmlContent table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblHtmlContent_Insert
(

	@Id int    OUTPUT,

	@Name nvarchar (128)  ,

	@Summary ntext   ,

	@Content ntext   ,

	@LanguageId int   ,

	@TypeId int   ,

	@Status char (1)  ,

	@CreatedDate datetime   ,

	@CreatedBy varchar (50)  ,

	@ModifiedDate datetime   ,

	@ModifiedBy varchar (50)  ,

	@ApprovedDate datetime   ,

	@ApprovedBy varchar (50)  ,

	@Tags nvarchar (1024)  
)
AS


				
				INSERT INTO [dbo].[tblHtmlContent]
					(
					[Name]
					,[Summary]
					,[Content]
					,[LanguageId]
					,[TypeId]
					,[Status]
					,[CreatedDate]
					,[CreatedBy]
					,[ModifiedDate]
					,[ModifiedBy]
					,[ApprovedDate]
					,[ApprovedBy]
					,[Tags]
					)
				VALUES
					(
					@Name
					,@Summary
					,@Content
					,@LanguageId
					,@TypeId
					,@Status
					,@CreatedDate
					,@CreatedBy
					,@ModifiedDate
					,@ModifiedBy
					,@ApprovedDate
					,@ApprovedBy
					,@Tags
					)
				
				-- Get the identity value
				SET @Id = SCOPE_IDENTITY()
									
							
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblHtmlContent_Update procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblHtmlContent_Update') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblHtmlContent_Update
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Updates a record in the tblHtmlContent table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblHtmlContent_Update
(

	@Id int   ,

	@Name nvarchar (128)  ,

	@Summary ntext   ,

	@Content ntext   ,

	@LanguageId int   ,

	@TypeId int   ,

	@Status char (1)  ,

	@CreatedDate datetime   ,

	@CreatedBy varchar (50)  ,

	@ModifiedDate datetime   ,

	@ModifiedBy varchar (50)  ,

	@ApprovedDate datetime   ,

	@ApprovedBy varchar (50)  ,

	@Tags nvarchar (1024)  
)
AS


				
				
				-- Modify the updatable columns
				UPDATE
					[dbo].[tblHtmlContent]
				SET
					[Name] = @Name
					,[Summary] = @Summary
					,[Content] = @Content
					,[LanguageId] = @LanguageId
					,[TypeId] = @TypeId
					,[Status] = @Status
					,[CreatedDate] = @CreatedDate
					,[CreatedBy] = @CreatedBy
					,[ModifiedDate] = @ModifiedDate
					,[ModifiedBy] = @ModifiedBy
					,[ApprovedDate] = @ApprovedDate
					,[ApprovedBy] = @ApprovedBy
					,[Tags] = @Tags
				WHERE
[Id] = @Id 
				
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblHtmlContent_Delete procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblHtmlContent_Delete') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblHtmlContent_Delete
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Deletes a record in the tblHtmlContent table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblHtmlContent_Delete
(

	@Id int   
)
AS


				DELETE FROM [dbo].[tblHtmlContent] WITH (ROWLOCK) 
				WHERE
					[Id] = @Id
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblHtmlContent_GetByTypeId procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblHtmlContent_GetByTypeId') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblHtmlContent_GetByTypeId
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Select records from the tblHtmlContent table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblHtmlContent_GetByTypeId
(

	@TypeId int   
)
AS


				SET ANSI_NULLS OFF
				
				SELECT
					[Id],
					[Name],
					[Summary],
					[Content],
					[LanguageId],
					[TypeId],
					[Status],
					[CreatedDate],
					[CreatedBy],
					[ModifiedDate],
					[ModifiedBy],
					[ApprovedDate],
					[ApprovedBy],
					[Tags]
				FROM
					[dbo].[tblHtmlContent]
				WHERE
					[TypeId] = @TypeId
				
				SELECT @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblHtmlContent_GetByLanguageId procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblHtmlContent_GetByLanguageId') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblHtmlContent_GetByLanguageId
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Select records from the tblHtmlContent table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblHtmlContent_GetByLanguageId
(

	@LanguageId int   
)
AS


				SET ANSI_NULLS OFF
				
				SELECT
					[Id],
					[Name],
					[Summary],
					[Content],
					[LanguageId],
					[TypeId],
					[Status],
					[CreatedDate],
					[CreatedBy],
					[ModifiedDate],
					[ModifiedBy],
					[ApprovedDate],
					[ApprovedBy],
					[Tags]
				FROM
					[dbo].[tblHtmlContent]
				WHERE
					[LanguageId] = @LanguageId
				
				SELECT @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblHtmlContent_GetById procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblHtmlContent_GetById') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblHtmlContent_GetById
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Select records from the tblHtmlContent table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblHtmlContent_GetById
(

	@Id int   
)
AS


				SELECT
					[Id],
					[Name],
					[Summary],
					[Content],
					[LanguageId],
					[TypeId],
					[Status],
					[CreatedDate],
					[CreatedBy],
					[ModifiedDate],
					[ModifiedBy],
					[ApprovedDate],
					[ApprovedBy],
					[Tags]
				FROM
					[dbo].[tblHtmlContent]
				WHERE
					[Id] = @Id
				SELECT @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblHtmlContent_Find procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblHtmlContent_Find') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblHtmlContent_Find
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Finds records in the tblHtmlContent table passing nullable parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblHtmlContent_Find
(

	@SearchUsingOR bit   = null ,

	@Id int   = null ,

	@Name nvarchar (128)  = null ,

	@Summary ntext   = null ,

	@Content ntext   = null ,

	@LanguageId int   = null ,

	@TypeId int   = null ,

	@Status char (1)  = null ,

	@CreatedDate datetime   = null ,

	@CreatedBy varchar (50)  = null ,

	@ModifiedDate datetime   = null ,

	@ModifiedBy varchar (50)  = null ,

	@ApprovedDate datetime   = null ,

	@ApprovedBy varchar (50)  = null ,

	@Tags nvarchar (1024)  = null 
)
AS


				
  IF ISNULL(@SearchUsingOR, 0) <> 1
  BEGIN
    SELECT
	  [Id]
	, [Name]
	, [Summary]
	, [Content]
	, [LanguageId]
	, [TypeId]
	, [Status]
	, [CreatedDate]
	, [CreatedBy]
	, [ModifiedDate]
	, [ModifiedBy]
	, [ApprovedDate]
	, [ApprovedBy]
	, [Tags]
    FROM
	[dbo].[tblHtmlContent]
    WHERE 
	 ([Id] = @Id OR @Id IS NULL)
	AND ([Name] = @Name OR @Name IS NULL)
	AND ([LanguageId] = @LanguageId OR @LanguageId IS NULL)
	AND ([TypeId] = @TypeId OR @TypeId IS NULL)
	AND ([Status] = @Status OR @Status IS NULL)
	AND ([CreatedDate] = @CreatedDate OR @CreatedDate IS NULL)
	AND ([CreatedBy] = @CreatedBy OR @CreatedBy IS NULL)
	AND ([ModifiedDate] = @ModifiedDate OR @ModifiedDate IS NULL)
	AND ([ModifiedBy] = @ModifiedBy OR @ModifiedBy IS NULL)
	AND ([ApprovedDate] = @ApprovedDate OR @ApprovedDate IS NULL)
	AND ([ApprovedBy] = @ApprovedBy OR @ApprovedBy IS NULL)
	AND ([Tags] = @Tags OR @Tags IS NULL)
						
  END
  ELSE
  BEGIN
    SELECT
	  [Id]
	, [Name]
	, [Summary]
	, [Content]
	, [LanguageId]
	, [TypeId]
	, [Status]
	, [CreatedDate]
	, [CreatedBy]
	, [ModifiedDate]
	, [ModifiedBy]
	, [ApprovedDate]
	, [ApprovedBy]
	, [Tags]
    FROM
	[dbo].[tblHtmlContent]
    WHERE 
	 ([Id] = @Id AND @Id is not null)
	OR ([Name] = @Name AND @Name is not null)
	OR ([LanguageId] = @LanguageId AND @LanguageId is not null)
	OR ([TypeId] = @TypeId AND @TypeId is not null)
	OR ([Status] = @Status AND @Status is not null)
	OR ([CreatedDate] = @CreatedDate AND @CreatedDate is not null)
	OR ([CreatedBy] = @CreatedBy AND @CreatedBy is not null)
	OR ([ModifiedDate] = @ModifiedDate AND @ModifiedDate is not null)
	OR ([ModifiedBy] = @ModifiedBy AND @ModifiedBy is not null)
	OR ([ApprovedDate] = @ApprovedDate AND @ApprovedDate is not null)
	OR ([ApprovedBy] = @ApprovedBy AND @ApprovedBy is not null)
	OR ([Tags] = @Tags AND @Tags is not null)
	SELECT @@ROWCOUNT			
  END
				

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblMenuType_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblMenuType_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblMenuType_Get_List
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Gets all records from the tblMenuType table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblMenuType_Get_List

AS


				
				SELECT
					[Id],
					[Code],
					[Name],
					[Position]
				FROM
					[dbo].[tblMenuType]
					
				SELECT @@ROWCOUNT
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblMenuType_GetPaged procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblMenuType_GetPaged') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblMenuType_GetPaged
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Gets records from the tblMenuType table passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblMenuType_GetPaged
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				
				BEGIN
				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				-- Create a temp table to store the select results
				CREATE TABLE #PageIndex
				(
				    [IndexId] int IDENTITY (1, 1) NOT NULL,
				    [Id] int 
				)
				
				-- Insert into the temp table
				DECLARE @SQL AS nvarchar(4000)
				SET @SQL = 'INSERT INTO #PageIndex ([Id])'
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + CONVERT(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' [Id]'
				SET @SQL = @SQL + ' FROM [dbo].[tblMenuType]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				IF LEN(@OrderBy) > 0
				BEGIN
					SET @SQL = @SQL + ' ORDER BY ' + @OrderBy
				END
				
				-- Populate the temp table
				EXEC sp_executesql @SQL

				-- Return paged results
				SELECT O.[Id], O.[Code], O.[Name], O.[Position]
				FROM
				    [dbo].[tblMenuType] O,
				    #PageIndex PageIndex
				WHERE
				    PageIndex.IndexId > @PageLowerBound
					AND O.[Id] = PageIndex.[Id]
				ORDER BY
				    PageIndex.IndexId
				
				-- get row count
				SET @SQL = 'SELECT COUNT(*) AS TotalRowCount'
				SET @SQL = @SQL + ' FROM [dbo].[tblMenuType]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				EXEC sp_executesql @SQL
			
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblMenuType_Insert procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblMenuType_Insert') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblMenuType_Insert
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Inserts a record into the tblMenuType table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblMenuType_Insert
(

	@Id int    OUTPUT,

	@Code varchar (50)  ,

	@Name nvarchar (128)  ,

	@Position int   
)
AS


				
				INSERT INTO [dbo].[tblMenuType]
					(
					[Code]
					,[Name]
					,[Position]
					)
				VALUES
					(
					@Code
					,@Name
					,@Position
					)
				
				-- Get the identity value
				SET @Id = SCOPE_IDENTITY()
									
							
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblMenuType_Update procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblMenuType_Update') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblMenuType_Update
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Updates a record in the tblMenuType table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblMenuType_Update
(

	@Id int   ,

	@Code varchar (50)  ,

	@Name nvarchar (128)  ,

	@Position int   
)
AS


				
				
				-- Modify the updatable columns
				UPDATE
					[dbo].[tblMenuType]
				SET
					[Code] = @Code
					,[Name] = @Name
					,[Position] = @Position
				WHERE
[Id] = @Id 
				
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblMenuType_Delete procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblMenuType_Delete') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblMenuType_Delete
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Deletes a record in the tblMenuType table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblMenuType_Delete
(

	@Id int   
)
AS


				DELETE FROM [dbo].[tblMenuType] WITH (ROWLOCK) 
				WHERE
					[Id] = @Id
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblMenuType_GetById procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblMenuType_GetById') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblMenuType_GetById
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Select records from the tblMenuType table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblMenuType_GetById
(

	@Id int   
)
AS


				SELECT
					[Id],
					[Code],
					[Name],
					[Position]
				FROM
					[dbo].[tblMenuType]
				WHERE
					[Id] = @Id
				SELECT @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblMenuType_GetByCode procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblMenuType_GetByCode') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblMenuType_GetByCode
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Select records from the tblMenuType table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblMenuType_GetByCode
(

	@Code varchar (50)  
)
AS


				SELECT
					[Id],
					[Code],
					[Name],
					[Position]
				FROM
					[dbo].[tblMenuType]
				WHERE
					[Code] = @Code
				SELECT @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblMenuType_Find procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblMenuType_Find') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblMenuType_Find
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Finds records in the tblMenuType table passing nullable parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblMenuType_Find
(

	@SearchUsingOR bit   = null ,

	@Id int   = null ,

	@Code varchar (50)  = null ,

	@Name nvarchar (128)  = null ,

	@Position int   = null 
)
AS


				
  IF ISNULL(@SearchUsingOR, 0) <> 1
  BEGIN
    SELECT
	  [Id]
	, [Code]
	, [Name]
	, [Position]
    FROM
	[dbo].[tblMenuType]
    WHERE 
	 ([Id] = @Id OR @Id IS NULL)
	AND ([Code] = @Code OR @Code IS NULL)
	AND ([Name] = @Name OR @Name IS NULL)
	AND ([Position] = @Position OR @Position IS NULL)
						
  END
  ELSE
  BEGIN
    SELECT
	  [Id]
	, [Code]
	, [Name]
	, [Position]
    FROM
	[dbo].[tblMenuType]
    WHERE 
	 ([Id] = @Id AND @Id is not null)
	OR ([Code] = @Code AND @Code is not null)
	OR ([Name] = @Name AND @Name is not null)
	OR ([Position] = @Position AND @Position is not null)
	SELECT @@ROWCOUNT			
  END
				

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblGroupPermission_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblGroupPermission_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblGroupPermission_Get_List
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Gets all records from the tblGroupPermission table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblGroupPermission_Get_List

AS


				
				SELECT
					[Id],
					[GroupId],
					[FunctionId],
					[Permission]
				FROM
					[dbo].[tblGroupPermission]
					
				SELECT @@ROWCOUNT
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblGroupPermission_GetPaged procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblGroupPermission_GetPaged') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblGroupPermission_GetPaged
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Gets records from the tblGroupPermission table passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblGroupPermission_GetPaged
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				
				BEGIN
				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				-- Create a temp table to store the select results
				CREATE TABLE #PageIndex
				(
				    [IndexId] int IDENTITY (1, 1) NOT NULL,
				    [Id] int 
				)
				
				-- Insert into the temp table
				DECLARE @SQL AS nvarchar(4000)
				SET @SQL = 'INSERT INTO #PageIndex ([Id])'
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + CONVERT(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' [Id]'
				SET @SQL = @SQL + ' FROM [dbo].[tblGroupPermission]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				IF LEN(@OrderBy) > 0
				BEGIN
					SET @SQL = @SQL + ' ORDER BY ' + @OrderBy
				END
				
				-- Populate the temp table
				EXEC sp_executesql @SQL

				-- Return paged results
				SELECT O.[Id], O.[GroupId], O.[FunctionId], O.[Permission]
				FROM
				    [dbo].[tblGroupPermission] O,
				    #PageIndex PageIndex
				WHERE
				    PageIndex.IndexId > @PageLowerBound
					AND O.[Id] = PageIndex.[Id]
				ORDER BY
				    PageIndex.IndexId
				
				-- get row count
				SET @SQL = 'SELECT COUNT(*) AS TotalRowCount'
				SET @SQL = @SQL + ' FROM [dbo].[tblGroupPermission]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				EXEC sp_executesql @SQL
			
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblGroupPermission_Insert procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblGroupPermission_Insert') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblGroupPermission_Insert
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Inserts a record into the tblGroupPermission table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblGroupPermission_Insert
(

	@Id int    OUTPUT,

	@GroupId int   ,

	@FunctionId int   ,

	@Permission int   
)
AS


				
				INSERT INTO [dbo].[tblGroupPermission]
					(
					[GroupId]
					,[FunctionId]
					,[Permission]
					)
				VALUES
					(
					@GroupId
					,@FunctionId
					,@Permission
					)
				
				-- Get the identity value
				SET @Id = SCOPE_IDENTITY()
									
							
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblGroupPermission_Update procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblGroupPermission_Update') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblGroupPermission_Update
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Updates a record in the tblGroupPermission table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblGroupPermission_Update
(

	@Id int   ,

	@GroupId int   ,

	@FunctionId int   ,

	@Permission int   
)
AS


				
				
				-- Modify the updatable columns
				UPDATE
					[dbo].[tblGroupPermission]
				SET
					[GroupId] = @GroupId
					,[FunctionId] = @FunctionId
					,[Permission] = @Permission
				WHERE
[Id] = @Id 
				
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblGroupPermission_Delete procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblGroupPermission_Delete') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblGroupPermission_Delete
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Deletes a record in the tblGroupPermission table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblGroupPermission_Delete
(

	@Id int   
)
AS


				DELETE FROM [dbo].[tblGroupPermission] WITH (ROWLOCK) 
				WHERE
					[Id] = @Id
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblGroupPermission_GetByFunctionId procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblGroupPermission_GetByFunctionId') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblGroupPermission_GetByFunctionId
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Select records from the tblGroupPermission table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblGroupPermission_GetByFunctionId
(

	@FunctionId int   
)
AS


				SET ANSI_NULLS OFF
				
				SELECT
					[Id],
					[GroupId],
					[FunctionId],
					[Permission]
				FROM
					[dbo].[tblGroupPermission]
				WHERE
					[FunctionId] = @FunctionId
				
				SELECT @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblGroupPermission_GetByGroupId procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblGroupPermission_GetByGroupId') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblGroupPermission_GetByGroupId
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Select records from the tblGroupPermission table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblGroupPermission_GetByGroupId
(

	@GroupId int   
)
AS


				SET ANSI_NULLS OFF
				
				SELECT
					[Id],
					[GroupId],
					[FunctionId],
					[Permission]
				FROM
					[dbo].[tblGroupPermission]
				WHERE
					[GroupId] = @GroupId
				
				SELECT @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblGroupPermission_GetById procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblGroupPermission_GetById') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblGroupPermission_GetById
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Select records from the tblGroupPermission table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblGroupPermission_GetById
(

	@Id int   
)
AS


				SELECT
					[Id],
					[GroupId],
					[FunctionId],
					[Permission]
				FROM
					[dbo].[tblGroupPermission]
				WHERE
					[Id] = @Id
				SELECT @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblGroupPermission_Find procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblGroupPermission_Find') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblGroupPermission_Find
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Finds records in the tblGroupPermission table passing nullable parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblGroupPermission_Find
(

	@SearchUsingOR bit   = null ,

	@Id int   = null ,

	@GroupId int   = null ,

	@FunctionId int   = null ,

	@Permission int   = null 
)
AS


				
  IF ISNULL(@SearchUsingOR, 0) <> 1
  BEGIN
    SELECT
	  [Id]
	, [GroupId]
	, [FunctionId]
	, [Permission]
    FROM
	[dbo].[tblGroupPermission]
    WHERE 
	 ([Id] = @Id OR @Id IS NULL)
	AND ([GroupId] = @GroupId OR @GroupId IS NULL)
	AND ([FunctionId] = @FunctionId OR @FunctionId IS NULL)
	AND ([Permission] = @Permission OR @Permission IS NULL)
						
  END
  ELSE
  BEGIN
    SELECT
	  [Id]
	, [GroupId]
	, [FunctionId]
	, [Permission]
    FROM
	[dbo].[tblGroupPermission]
    WHERE 
	 ([Id] = @Id AND @Id is not null)
	OR ([GroupId] = @GroupId AND @GroupId is not null)
	OR ([FunctionId] = @FunctionId AND @FunctionId is not null)
	OR ([Permission] = @Permission AND @Permission is not null)
	SELECT @@ROWCOUNT			
  END
				

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

